Let’s imagine that the maximum element is divisible by 2, 3 and 5 and there are three following numbers in the array: maximum divided by 2, by 3 and by 5. Then their sum is greater than the maximum (and may be greater than the answer we have!) because 1/2 + 1/3 + 1 / 5 > 1
@_@ 别问我为啥,我啥也不知道
#include<bits/stdc++.h>#include<bits/extc++.h>#define oo INT_MAX#define maxn 10000009 #define _rep(i, a, b) for(int i = (a); i <= (b); ++i)#define _rev(i, a, b) for(int i = (a); i >= (b); --i)#define _for(i, a, b) for(int i = (a); i < (b) ;++i)#define met(a, b) memset(a, b, sizeof(a))usingnamespace std;usingnamespace __gnu_pbds;intmain(){
ios::sync_with_stdio(0);int t;
cin >> t;while(t --){int n;
cin >> n;
set<int> s;_rep(i,1, n){int xx;
cin >> xx;
s.insert(xx);}int ans =0;int max_val =*s.rbegin();if(max_val %5==0&& max_val %2==0&& max_val %3==0&& s.count(max_val /5)&& s.count(max_val /3)&& s.count(max_val /2)){
ans =max(max_val, max_val /3+ max_val /5+ max_val /2);}
vector<int> res;while(!s.empty()&&int(res.size())<3){int max_val =*s.rbegin();
s.erase(prev(s.end()));bool isnt_devided =1;for(auto x : res) isnt_devided &=(x % max_val !=0);if(isnt_devided) res.push_back(max_val);}
cout <<max(ans,accumulate(res.begin(), res.end(),0))<< endl;}//system("pause");}