#include <cstdio>
#include <cstring>
int cnt[210001];
int main() {
int N;
int res=0;
memset(cnt,0,sizeof(cnt));
scanf("%d",&N);
for (int i=0; i<N; ++i) {
int a;
scanf("%d",&a);
cnt[a]++;
}
for (int i=0; i<210000; ++i) {
cnt[i+1] += cnt[i]/2;
if (cnt[i]>0) res=i;
}
printf("%d\n",res);
return 0;
}
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 | #include <cstdio> #include <cstring> int cnt[210001]; int main() { int N; int res=0; memset(cnt,0,sizeof(cnt)); scanf("%d",&N); for (int i=0; i<N; ++i) { int a; scanf("%d",&a); cnt[a]++; } for (int i=0; i<210000; ++i) { cnt[i+1] += cnt[i]/2; if (cnt[i]>0) res=i; } printf("%d\n",res); return 0; } |
English