#include <cstdio> #include <algorithm> using namespace std; const int MAXA = 1 << 19; int c[MAXA + 1]; int main() { int n, a; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a); c[a]++; } int ans = 0; for (int i = 0; i < MAXA; ++i) { if (c[i] > 0) ans = i; c[i + 1] += c[i] / 2; } printf("%d\n", ans); }
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 <cstdio> #include <algorithm> using namespace std; const int MAXA = 1 << 19; int c[MAXA + 1]; int main() { int n, a; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a); c[a]++; } int ans = 0; for (int i = 0; i < MAXA; ++i) { if (c[i] > 0) ans = i; c[i + 1] += c[i] / 2; } printf("%d\n", ans); } |