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

const int MW = 300005;

int ile[MW];

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		int a;
		scanf("%d", &a);
		++ile[a];
	}
	int res = 0;
	for(int i = 0; i < MW; ++i)
	{
		if(ile[i]) res = i;
		ile[i + 1] += (ile[i] >> 1);
	}
	printf("%d", res);
}