#include <cstdio> const int N = 210000; int cnt[N]; int main() { int m; for (scanf("%d", &m); m--;) { int a; scanf("%d", &a); ++cnt[a]; } for (int i = 0; i + 1 < N; ++i) cnt[i + 1] += cnt[i] >> 1, cnt[i] &= 1; for (int i = N - 1; i >= 0; --i) if (cnt[i]) return printf("%d\n", i), 0; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <cstdio> const int N = 210000; int cnt[N]; int main() { int m; for (scanf("%d", &m); m--;) { int a; scanf("%d", &a); ++cnt[a]; } for (int i = 0; i + 1 < N; ++i) cnt[i + 1] += cnt[i] >> 1, cnt[i] &= 1; for (int i = N - 1; i >= 0; --i) if (cnt[i]) return printf("%d\n", i), 0; return 0; } |