#include <iostream> #include <cstdio> using namespace std; int lot[ 202000 ]; int main() { int n, x, maks = 0; scanf( "%d", &n ); for ( int i = 0; i < n; ++i ) { scanf( "%d", &x ); if ( x > maks ) maks = x; lot[ x ]++; } for ( int i = 0; i <= maks; ++i ) { lot[ i + 1 ] += lot[ i ] / 2; if ( i == maks && lot[ i + 1 ] ) maks++; } printf( "%d", maks ); }
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 | #include <iostream> #include <cstdio> using namespace std; int lot[ 202000 ]; int main() { int n, x, maks = 0; scanf( "%d", &n ); for ( int i = 0; i < n; ++i ) { scanf( "%d", &x ); if ( x > maks ) maks = x; lot[ x ]++; } for ( int i = 0; i <= maks; ++i ) { lot[ i + 1 ] += lot[ i ] / 2; if ( i == maks && lot[ i + 1 ] ) maks++; } printf( "%d", maks ); } |