1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;

const int MAXW = 201718 + 20;

int a, n, w, W[MAXW + 1];

int main() {
    scanf("%d", &n);
    while (n--) {
        scanf("%d", &a);
        ++W[a];
    }
    for (int i = 0; i < MAXW; ++i) {
        W[i + 1] += W[i] / 2;
        if (W[i + 1] > 0) {
            w = i + 1;
        }
    }
    cout << w << endl;
    return 0;
}