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

using namespace std;

const int MAX_SIZE = 201718 + 24;
vector<int> skarbonka = vector<int>(MAX_SIZE);


int main()
{
    int n, i, b;
    int maksNominal;
    
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> b;
        skarbonka[b] ++;
    }
    
    maksNominal = 0;
    for (i = 0; i < MAX_SIZE; i++) {
        b = skarbonka[i];
        if (b > 0) {
            maksNominal = i;
            skarbonka[i + 1] += b / 2;
        }
    }
    
    cout << maksNominal;
    
	return 0;
}