#include <cstdio> #include <algorithm> bool coin[201718+1+20]; int N; int largest = 0; int main() { scanf("%d", &N); for (int i=0; i<N; i++) { int x; scanf("%d", &x); while (coin[x]) coin[x] = false, x++; coin[x] = true; largest = std::max(largest, x); } printf("%d\n", largest); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <cstdio> #include <algorithm> bool coin[201718+1+20]; int N; int largest = 0; int main() { scanf("%d", &N); for (int i=0; i<N; i++) { int x; scanf("%d", &x); while (coin[x]) coin[x] = false, x++; coin[x] = true; largest = std::max(largest, x); } printf("%d\n", largest); return 0; } |