#include <cstdio> const int MAX_A = 201718 + 20; // max ai + log2(1 000 000) int main() { int n, t; int A[MAX_A] = {0}; scanf("%d", &n); while (n--) { scanf("%d", &t); ++A[t]; } int max_ai = 0; for (int i = 0; i < MAX_A; ++i) { if (A[i] > 1) A[i+1] += A[i] / 2; if (A[i]) max_ai = i; } printf("%d\n", max_ai); 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 | #include <cstdio> const int MAX_A = 201718 + 20; // max ai + log2(1 000 000) int main() { int n, t; int A[MAX_A] = {0}; scanf("%d", &n); while (n--) { scanf("%d", &t); ++A[t]; } int max_ai = 0; for (int i = 0; i < MAX_A; ++i) { if (A[i] > 1) A[i+1] += A[i] / 2; if (A[i]) max_ai = i; } printf("%d\n", max_ai); return 0; } |