#include <iostream> #include <cmath> using namespace std; int t[203000]; int main() { int l; cin >> l; int x; int w=0,nb=0; for(int i=0;i<l;i++){ cin >> x; t[x] ++ ; int jj=0; while(t[x+jj] >= 2){ t[x] = 0; jj++; t[x+jj]++; } } for(int i=202500;i>=0;i--){ if(t[i]>0){ cout << i; i = 0; 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 | #include <iostream> #include <cmath> using namespace std; int t[203000]; int main() { int l; cin >> l; int x; int w=0,nb=0; for(int i=0;i<l;i++){ cin >> x; t[x] ++ ; int jj=0; while(t[x+jj] >= 2){ t[x] = 0; jj++; t[x+jj]++; } } for(int i=202500;i>=0;i--){ if(t[i]>0){ cout << i; i = 0; break; } } return 0; } |