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
28
29
30
31
32
33
34
35
36
37
#include <cstdint>
#include <iostream>

using namespace std;

const uint32_t MaxA = 201718;

int main() {
    uint32_t i, n, a, top, topVal, log2, ans;
    uint32_t arr[MaxA + 1] = { 0 };

    cin >> n;

    for (i = 0; i < n; ++i) {
        cin >> a;
        ++arr[a];
    }

    top = 0;
    for (i = 0; i < MaxA; ++i) {
        arr[i + 1] += arr[i] / 2;
        if (arr[i + 1]) {
            top = i + 1;
        }
    }

    topVal = arr[top];
    log2 = 0;
    while (topVal >>= 1) {
        ++log2;
    }

    ans = top + log2;
    cout << ans;

    return 0;
}