#include <iostream> using namespace std; const int kTableSize = 1000000; int main(int argc, const char * argv[]) { int n; int value; cin >> n; int monety[kTableSize]; for ( int i = 0; i < kTableSize; i++ ) monety[i] = 0; while ( n-- ) { cin >> value; monety[value]++; while ( monety[value] == 2 ) { monety[value] = 0; value++; monety[value]++; } } int i = kTableSize-1; while ( monety[i] == 0 ) i--; cout << i << endl; }
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> using namespace std; const int kTableSize = 1000000; int main(int argc, const char * argv[]) { int n; int value; cin >> n; int monety[kTableSize]; for ( int i = 0; i < kTableSize; i++ ) monety[i] = 0; while ( n-- ) { cin >> value; monety[value]++; while ( monety[value] == 2 ) { monety[value] = 0; value++; monety[value]++; } } int i = kTableSize-1; while ( monety[i] == 0 ) i--; cout << i << endl; } |