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<array>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    static array<int, 201720> buckets;
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        ++buckets[x];
    }
    int res = -1;
    for (int i = 1; i < buckets.size(); ++i) {
        buckets[i] += buckets[i - 1] / 2;
        if (buckets[i] > 0) {
            res = i;
        }
    }
    printf("%d\n", res);
    return 0;
}