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

using namespace std;

int main() {

    int coin_count[201720] = {0};
    int n;
    cin >> n;
    int max_temp = 0;
    for (int count = 0; count < n; count++) {
        int temp;
        cin >> temp;
        coin_count[temp]++;
    }
    for (int count = 0; count <= 201720; count++) {
        if (coin_count[count] > 0) {
            int temp = coin_count[count];
            coin_count[count] = temp % 2;
            coin_count[count + 1] += temp / 2;
            if (coin_count[count] > 0) {
                max_temp = count;
            }
        }
    }

    cout << max_temp;
    cout << '\n';
    return 0;
}