1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include <iostream>
using namespace std;
int a, b, c, d, e, t[202000];
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> a; for (int i=1; i<=a; i++) {cin >> b; t[b]++; if (b>c) c=b;}
    while ((t[d]>0)||(d<c)) {t[d+1]=t[d+1]+t[d]/2; d++;}
    cout << d-1;
    return(0);
}