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
38
39
40
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <stdlib.h>

constexpr int max_power_of_two = 210000;

int power_of_twos[max_power_of_two] = {0};


int main() {
    int n;

    std::scanf("%d", &n);

    for(int i = 0; i < n; ++i) {
        int now;
        std::scanf("%d", &now);
        power_of_twos[now]++;
    }

    int max_value = 0;

    for(int i = 0; i < max_power_of_two; ++i) {
        if (power_of_twos[i] > 0) {
            max_value = i;
        }

        auto div = std::div(power_of_twos[i], 2);

        power_of_twos[i] = div.rem;
        if (div.quot > 0) {
            power_of_twos[i + 1] += div.quot;
        }
    }

    printf("%d\n", max_value);

    return 0;
}