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
#include <cstdio>
#include <map>

using namespace std;

typedef map<int,int> MII;

int main()
{
    int N;
    scanf("%d", &N);
    MII mii;
    for (int i = 0; i < N; ++i)
    {
        int v;
        scanf("%d", &v);
        ++mii[v];
    }
    int last = -1;
    MII::iterator it = mii.begin();
    while (it != mii.end())
    {
        last = it->first;
        int add = it->second / 2;
        if (add)
            mii[it->first + 1] += add;
        ++it;
    }
    printf("%d\n", last);
}