#include <cstdio> int main() { int a[201739]; for (int i = 0; i < 201739; i++) { a[i] = 0; } int n; int ai; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &ai); a[ai]++; } int carry = 0; for (int i = 0; i < 201739; i++) { a[i] += carry; if (a[i] > 1) { if ((a[i] & 1) == 0) { carry = a[i]; a[i] = 0; } else { carry = a[i] - 1; a[i] = 1; } } carry /= 2; } for (int i = 201738; i >= 0; i--) { if (a[i] > 0) { printf("%d\n", i); break; } } 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 33 34 35 36 37 | #include <cstdio> int main() { int a[201739]; for (int i = 0; i < 201739; i++) { a[i] = 0; } int n; int ai; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &ai); a[ai]++; } int carry = 0; for (int i = 0; i < 201739; i++) { a[i] += carry; if (a[i] > 1) { if ((a[i] & 1) == 0) { carry = a[i]; a[i] = 0; } else { carry = a[i] - 1; a[i] = 1; } } carry /= 2; } for (int i = 201738; i >= 0; i--) { if (a[i] > 0) { printf("%d\n", i); break; } } return 0; } |