#include<iostream> #include<cstdio> using namespace std; int tab[2000000]; int main() { int n, i, wyn = 0, a, maks = 0; scanf("%d",&n); for(i = 0; i < n; ++i) { scanf("%d",&a); tab[a]++; maks = max(maks,a); } for(i = 1; i <= maks; ++i) { tab[i] += tab[i-1]/2; } while(tab[i-1] > 0){ tab[i] += tab[i-1]/2; if(tab[i] == 1) maks = i; ++i; } //for(int j = 0; j <= maks + 5; ++j) printf("%d ",tab[j]); printf("%d",maks); 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<iostream> #include<cstdio> using namespace std; int tab[2000000]; int main() { int n, i, wyn = 0, a, maks = 0; scanf("%d",&n); for(i = 0; i < n; ++i) { scanf("%d",&a); tab[a]++; maks = max(maks,a); } for(i = 1; i <= maks; ++i) { tab[i] += tab[i-1]/2; } while(tab[i-1] > 0){ tab[i] += tab[i-1]/2; if(tab[i] == 1) maks = i; ++i; } //for(int j = 0; j <= maks + 5; ++j) printf("%d ",tab[j]); printf("%d",maks); return 0; } |