#include<bits/stdc++.h>
#define lli long long
#define f first
#define s second
#define mod 1000000007
#define inf 1000000000
#define mp make_pair
#define pb push_back
using namespace std;
const int N=1000009;
const int M=100009;
lli t[N];
lli pot[20];
int main()
{
int n,maks=0;
lli wyn=0;
scanf("%d", &n);
for(int i=1;i<=n;i++) {int a;
scanf("%d", &a); t[a]++; maks=max(maks,a);}
int i=0;
while(i<=maks || (t[i]!=0 && i>maks))
{
t[i+1]+=t[i]/2;
t[i]%=2;
wyn=max(wyn,t[i]*i);
i++;
}
printf("%lld", wyn);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include<bits/stdc++.h> #define lli long long #define f first #define s second #define mod 1000000007 #define inf 1000000000 #define mp make_pair #define pb push_back using namespace std; const int N=1000009; const int M=100009; lli t[N]; lli pot[20]; int main() { int n,maks=0; lli wyn=0; scanf("%d", &n); for(int i=1;i<=n;i++) {int a; scanf("%d", &a); t[a]++; maks=max(maks,a);} int i=0; while(i<=maks || (t[i]!=0 && i>maks)) { t[i+1]+=t[i]/2; t[i]%=2; wyn=max(wyn,t[i]*i); i++; } printf("%lld", wyn); } |
English