1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int A[1100000];
int n,m;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		int k1; scanf("%d",&k1); A[k1]++; m=max(m,k1);
	}
	int flag=0;
	for (int i=0;i<m;i++) A[i+1]+=(A[i]/2);
	while (A[m]){
		A[m+1]=A[m]/2; m++;
	}
	printf("%d\n",m-1);
	return 0;
}