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: 68ms
Memory: 2500kB
In contest: 1276

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
int t,n,ans=0,m;
int x[maxn];
int a[maxn];
string s;
bool cmp(const int& a,const int& b)
{
	return a>b;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x[i]);
	}
	sort(x+1,x+1+n,cmp);
	ans=x[1];
	a[1]=x[1];
	m=1;
	for(int i=2;i<=n;i++)
	{
		if(x[i]==1)break;
		if(x[i]!=x[i-1])
		{
			m++;
			a[m]=x[i];
		}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=i+1;j<=m;j++)
		{
			if(ans>=a[i]+a[j])break;
			if(a[i]%a[j]!=0)
			{
				ans=max(ans,a[i]+a[j]);
			}
		}
	}
	printf("%d\n",ans);
}