題目大意
給定
數字的個數和大小均小於200000
考試的時候發現這題A的比
首先,可以發現,對於一個基數
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
const int MAX = 200000+5;
const int N = MAX;
using namespace std;
typedef long long LL;
bool vis[N];
int sum[N],n,a[N];
inline int read()
{
int x=0,f=1;char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-')f=-1;ch = getchar();}
while(ch >='0' && ch <='9'){x=(x<<1)+(x<<3)+ch-'0';ch = getchar();}
return x*f;
}
int main()
{
int n = read();
for(int i=1;i<=n;++i) a[i] = read(),sum[a[i]] ++;
for(int i=MAX;i>=1;--i) sum[i]+= sum[i+1];
sort(a+1,a+n+1);
LL ans = 0;
for(int i=1;i<=n;++i)
{
if(vis[a[i]])continue;
int tt = MAX / a[i];
int times = 0;
LL tmpans = 0;
for(int j=tt;j>=1;--j)
{
int tmp = j * a[i];
vis[tmp] = 1;
tmpans += (LL)(sum[tmp] - times)*(LL)tmp;
times = sum[tmp];
}
ans = max(ans,tmpans);
}
cout << ans << endl;
}