1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

int main() {
	const int MAX = 300000;
	int n, x, a[MAX];

	for (int i = 0; i < MAX; ++i)
		a[i] = 0;

	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		std::cin >> x;
		++a[x];
	}

	int max = 0;
	for (int i = 0; i < MAX - 1; ++i) {
		if (a[i] != 0)
			max = i;
		a[i + 1] += a[i] / 2;
	}

	std::cout << max << std::endl;
}