#include <iostream> #include <cmath> using namespace std; int tab[1000000]; int tabSort[1000000]; int main() { ios_base::sync_with_stdio(false); int n = 0, sum = 0, wyn = 0, maxi = 0, inc = 1; cin>>n; for(int i=0; i<n; ++i){ cin>>tab[i]; } for(int i=0; i<n; ++i){ if(tab[i] > maxi){ maxi = tab[i]; } } for(int i = 0; i<maxi+1; ++i){ tabSort[i] = 0; } for(int i = 0; i<n; ++i){ tabSort[tab[i]]++; } for(int i = 0; i<maxi; ++i){ if(tabSort[i] > 1){ tabSort[i+1]+=floor(tabSort[i]/2); } } wyn = maxi; while(true){ if(tabSort[maxi] >= pow(2,inc)){ wyn++; inc++; } else{ cout<<wyn; break; } } 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <iostream> #include <cmath> using namespace std; int tab[1000000]; int tabSort[1000000]; int main() { ios_base::sync_with_stdio(false); int n = 0, sum = 0, wyn = 0, maxi = 0, inc = 1; cin>>n; for(int i=0; i<n; ++i){ cin>>tab[i]; } for(int i=0; i<n; ++i){ if(tab[i] > maxi){ maxi = tab[i]; } } for(int i = 0; i<maxi+1; ++i){ tabSort[i] = 0; } for(int i = 0; i<n; ++i){ tabSort[tab[i]]++; } for(int i = 0; i<maxi; ++i){ if(tabSort[i] > 1){ tabSort[i+1]+=floor(tabSort[i]/2); } } wyn = maxi; while(true){ if(tabSort[maxi] >= pow(2,inc)){ wyn++; inc++; } else{ cout<<wyn; break; } } return 0; } |