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: 69ms
Memory: 2108kB
In contest: 1276

#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;
int a[maxn]={0};
bool cmp(int a,int b){
	return a>b;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int ans=0;
	if(n==1)
		ans=a[0];
	else{
		sort(a,a+n,cmp);
		if(a[0]%a[1]!=0)
			ans=a[0]+a[1];
		else{
			ans=a[0];
			int pos=1;
			for(int i=1;i<n;i++){
				if(a[i-1]%a[i]!=0&&a[i-1]+a[i]>ans)
					ans=a[i]+a[i-1];
			}
		}

	}
	printf("%d\n",ans);
	return 0;
}