1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <stdio.h>

int main() {
	int n=0, i=0, tmp=0, best=0, mln=1000*1000;
	int arr[mln]; for (i=0; i<mln; i++) arr[i] = 0;
	scanf("%d\n", &n);
	for(i = 0; i<n; i++) {
		scanf("%d", &tmp);
		arr[tmp] += 1;
	}
	for (i=1; i<mln; i++) {
		arr[i]  += arr[i-1]/2;
		arr[i-1] = arr[i-1]%2;
		if (arr[i] > 0) best = i;
	}
	printf("%d\n", best);
	return 0;
};