1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cstdio>

int tab[1000007];

int main() {
    int N;
    scanf("%d", &N);
    int a;
    for (int i = 0; i < N; i++) {
        scanf("%d", &a);
        tab[a]++;
    }
    int maxi = 0;
    for (int i = 0; i < 1000000; i++) {
        tab[i + 1] += tab[i] / 2;
        if (tab[i] != 0)
            maxi = i;
    }
    printf("%d", maxi);
    return 0;
}