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
#include <iostream>

static const int MAX_VALUE = 201738;

int main() {
    int items, currentNum, response = 0;

    scanf("%d", &items);

    int* elements = new int[MAX_VALUE];

    for (int i = 0; i < items; i++) {
        scanf("%d", &currentNum);

        elements[currentNum] = elements[currentNum] + 1;
    }

    for (int i = 0; i < MAX_VALUE; i++) {
        if (elements[i] >= 1) {
            elements[i + 1] = elements[i + 1]  + (elements[i] / 2);

            response = i;
        }
    }

    printf("%d", response);

    return 0;
}