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
#include <stdio.h>

static const int MAX = 210719;
static int t[MAX];

int main(int argc, char* argv[]) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int v;
        scanf("%d", &v);
        t[v]++;
    }
    for (int i = 0; i < MAX - 1; ++i) {
        if (t[i] >= 2) {
            t[i + 1] += (t[i] / 2);
            t[i] = (t[i] % 2);
        }
    }
    for (int i = MAX - 1; i >= 0; i--) {
        if (t[i] > 0) {
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}