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
#include <cstdio>
#include <cstdlib>

static const int LIMIT = 201718 + 1000;

int nums[LIMIT] = { 0 };

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		int d;
		scanf("%d", &d);
		nums[d]++;
	}

	int ptr = 0;
	while (n > 1) {
		int old_nums = nums[ptr];
		int new_nums = old_nums / 2;
		nums[ptr + 1] += new_nums;
		n += new_nums - old_nums;
		ptr++;
	}

	while (nums[ptr] == 0) ptr++;

	printf("%d\n", ptr);

	return 0;
}