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
31
32
33
34
#include <cstdio>
#include <algorithm>


const int MAX = 1001000;
int n, coins[MAX];


int main(int argc, char *argv[]) {
	scanf("%d", &n);
	for (int c = 0; c < n; c++) {
		scanf("%d", coins + c);
	}
	std::sort(coins, coins + n);

	int r = 0;
	int num = 0;

	for (int c = 0; c < n; c++) {
		while (r < coins[c]) {
			num >>= 1;
			r++;
		}
		if (r == coins[c]) {
			num++;
		}
	}
	while (num > 1) {
		num >>= 1;
		r++;
	}

	printf("%i\n", r);
}