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>
//Patryk Tomaszewski
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector<int> a;
    int n, mn, mx;
    cin >> n;
    for(int i=0;i<n;i++) {
        int u;
        cin >> u;
        if(i==0) {
            mn=u;
            mx=u;
        }
        mn=min(u,mn);
        mx=max(u, mx);
        for(int j=a.size();j<u+1;j++) a.push_back(0);
        a[u]++;
    }
    int i=mn;
    while(i<mx || a[i]!=0) {
        if(a.size()<i+2) a.push_back(0);
        a[i+1]+=a[i]/2;
        i++;
    }
    cout << i-1;
    return 0;
}