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

using namespace std;

const int UPPER = 201999;

int main() {

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

	vector<int> quant(UPPER);

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

	for (int i = 0; i < UPPER - 1; ++i) {
		quant[i + 1] += quant[i] / 2;
	}

	for (int i = UPPER - 1; i >= 0; --i) {
		if (quant[i] != 0) {
			printf("%d\n", i);
			return 0;
		}
	}

	return 0;
}