Result: Accepted
Time: 66ms
Memory: 2108kB
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<cstring>
using namespace std;
const int maxn=1e5+100;
const int inf=0x3f3f3f3f;
int a[maxn];
int main(){
int n,q,tot=0;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);
tot=a[n-1];
for(int i=n-1;i>=0;i--){
if(a[i]==0) continue;
for(int j=i-1;j>=0;j--){
if(!a[j]) continue;
if(a[i]%a[j]!=0){
tot=max(tot,a[i]+a[j]);
a[j]=0;
break;
}
else a[j]=0;
}
}
printf("%d\n",tot);
}