#include <bits/stdc++.h>
using namespace std;
int n, sum;
int cnt[250007];
int main() {
scanf("%d", &n);
int a;
while(n--) {
scanf("%d", &a);
cnt[a]++;
}
sum = 0;
int res = 0;
for(int i = 0 ; i < 250000 ; i++) {
cnt[i + 1] += cnt[i] >> 1;
cnt[i] = cnt[i] & 1;
if(cnt[i])
res = max(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 27 28 29 | #include <bits/stdc++.h> using namespace std; int n, sum; int cnt[250007]; int main() { scanf("%d", &n); int a; while(n--) { scanf("%d", &a); cnt[a]++; } sum = 0; int res = 0; for(int i = 0 ; i < 250000 ; i++) { cnt[i + 1] += cnt[i] >> 1; cnt[i] = cnt[i] & 1; if(cnt[i]) res = max(res, i); } printf("%d\n", res); return 0; } |
English