Start: Jun, 28, 2019 08:42:00
2019杭州师范大学第一届程序设计竞赛新生赛
End: Jun, 28, 2019 11:42:00
Time elapsed:
Time remaining:

Problem_ID: H
Result: Accepted
Time: 123ms
Memory: 6264kB
In contest: 1276

#include<cstdio>
#include<set>
#include<vector>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
set<int>s;
set<int>::iterator it;
int a[maxn];
int main(){
	int n;
	ll maxx=0;
	while(~scanf("%d",&n)){
		int temp;
		for(int i=1;i<=n;i++){
			scanf("%d",&temp);
			s.insert(temp);
			if(temp>maxx)
				maxx=temp;
		}
		int pos=0;
		for(it=s.begin();it!=s.end();it++)
			a[pos++]=*it;
		for(int i=0;i<pos;i++){
			for(int j=pos-1;j>=0;j--){
				if(a[j]+a[i]<=maxx)break;
				if(a[j]%a[i]!=0&&a[i]%a[j]!=0)
					maxx=a[i]+a[j];
			}
		}
		printf("%lld\n",maxx);
	}
}