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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <vector>
#include<queue>
#include<algorithm>
using namespace std;
struct po
{
    int l;
    int ile=1;
};
int main()
{
    int n;
    po x;
    cin>>n;
    vector<int> a(n);
    queue<po>b;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    x.l=a[0];
    b.push(x);
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
            b.back().ile++;
        else
        {
            x.l=a[i];
            b.push(x);
        }
    }
    while(b.size()>=1)
    {
        if(b.front().ile%2==0)x.ile=b.front().ile/2;
        else x.ile=(b.front().ile-1)/2;
        x.l=b.front().l+1;
        b.pop();
        if(b.size()>1)
        {
            if(x.l==b.front().l)
            b.front().ile=b.front().ile+x.ile;
        }
    }

    cout<<x.l;
    return 0;
}