#include <iostream> #include <algorithm> using namespace std; const int MAX_POWER = 250 * 1000; int N; int POWERS[MAX_POWER]; int main() { ios_base::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { int a; cin >> a; POWERS[a]++; } int _max = 0; for (int i = 0; i < MAX_POWER - 3; i++) { if (POWERS[i] > 0) _max = i; POWERS[i + 1] += (POWERS[i]/2); } cout << _max; 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 | #include <iostream> #include <algorithm> using namespace std; const int MAX_POWER = 250 * 1000; int N; int POWERS[MAX_POWER]; int main() { ios_base::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { int a; cin >> a; POWERS[a]++; } int _max = 0; for (int i = 0; i < MAX_POWER - 3; i++) { if (POWERS[i] > 0) _max = i; POWERS[i + 1] += (POWERS[i]/2); } cout << _max; return 0; } |