#include <cstdio> #include <algorithm> using namespace std; constexpr int MAXA = 201800; int a[MAXA]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { int tmp; scanf("%d", &tmp); a[tmp]++; } int mx = 0; for (int i = 0; i < MAXA - 1; ++i) { if (a[i]) { mx = i; } a[i + 1] += a[i] / 2; } printf("%d\n", mx); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <cstdio> #include <algorithm> using namespace std; constexpr int MAXA = 201800; int a[MAXA]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { int tmp; scanf("%d", &tmp); a[tmp]++; } int mx = 0; for (int i = 0; i < MAXA - 1; ++i) { if (a[i]) { mx = i; } a[i + 1] += a[i] / 2; } printf("%d\n", mx); } |