#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
long long int tab[500000];
long long int wyn[500000];
int main() {
ios_base::sync_with_stdio(0);
int n, a, maxx = 0;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a;
tab[a]++;
maxx = max(maxx, a);
}
int x = 1;
while(x <= maxx) {
wyn[x] = tab[x] + (wyn[x-1]/2);
if(wyn[x] > 1) {
maxx = max(maxx, x+1);
}
x++;
}
cout << maxx;
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 <cstdio> #include <iostream> #include <algorithm> using namespace std; long long int tab[500000]; long long int wyn[500000]; int main() { ios_base::sync_with_stdio(0); int n, a, maxx = 0; cin >> n; for(int i = 1; i <= n; i++) { cin >> a; tab[a]++; maxx = max(maxx, a); } int x = 1; while(x <= maxx) { wyn[x] = tab[x] + (wyn[x-1]/2); if(wyn[x] > 1) { maxx = max(maxx, x+1); } x++; } cout << maxx; return 0; } |
English