#include <bits/stdc++.h>
using namespace std;
const int arrs = 205000;
int n;
int t[arrs];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
int a; scanf("%d", &a);
t[a]++;
}
for(int i = 1; i < arrs; ++i) {
t[i] += t[i-1]/2;
t[i-1] %= 2;
}
for(int i = arrs-1; i >= 0; --i) {
if(t[i]) {
printf("%d\n", i);
break;
}
}
}
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 | #include <bits/stdc++.h> using namespace std; const int arrs = 205000; int n; int t[arrs]; int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) { int a; scanf("%d", &a); t[a]++; } for(int i = 1; i < arrs; ++i) { t[i] += t[i-1]/2; t[i-1] %= 2; } for(int i = arrs-1; i >= 0; --i) { if(t[i]) { printf("%d\n", i); break; } } } |
English