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
#include <bits/stdc++.h>

using namespace std;

int in[250005];

int main()
{
    int n, x, res;
    scanf("%d", &n);

    for(int i = 0;i < n;++i)
    {
        scanf("%d", &x);
        ++in[x];
    }

    for(int i = 0;i < 250000;++i)
    {
        in[i+1] += in[i]>>1;
        if(in[i])
            res = i;
    }

    printf("%d\n", res);

    return 0;
}