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 <bits/stdc++.h>
using namespace std;

const int maxn = 1e6 + 10;

int n,ans;
int a[maxn];
int howMany[maxn];
int maxx;

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		maxx = max(maxx,a[i]);
	}
	sort(a, a + n);
    for(int i=0;i<n;i++)
    {
        howMany[a[i]]++;
    }
    for(int i=0;i<=maxx+1000;i++)
    {
        howMany[i+1] += howMany[i]/2;
        if(howMany[i]>0) ans = max(ans,i);
    }
    printf("%d\n",ans);
}