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

using std::cin;
using std::cout;
using std::endl;
using std::max;
using std::vector;


int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    vector<int> coins;
    coins.resize(220000, 0);

    int n, k, max_k = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> k;
        coins[k]++;
        max_k = max(max_k, k);
    }

    int index;
    for (int i = 0; i < max_k + 25; i++) {
        if (coins[i] > 0) {
            index = i;
            coins[i+1] += coins[i] / 2;
        }
    }
    cout << index << endl;
}