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

int c[201720];

int main() {
	int n;
	scanf("%d",&n);
	int m=0;
	for (int i=0;i<n;i++) {
		int a;
		scanf("%d",&a);
		//a=201718;
		if (a>m) m=a;
		c[a]++;
	}
	for (int i=0;i<m;i++)
		c[i+1] += c[i]/2;
	int ans=m;
	while (c[m]>1) {
		c[m] /= 2;
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}