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
35
#include <iostream>
#include <map>
#include <cstdio>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n, a;
	int m = -1;
	map<int, int> coins;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		coins[a]++;
		if (m < a) m = a;
	}

	int i = 1;
	bool hasValue = true;
	int ret = 1;
	while (true) {
		if (coins[i] > 0) ret = i;
		int pow2 = coins[i] / 2;
		coins[i + 1] += pow2;

		if (i >= m && pow2 == 0) break;
		i++;
	}

	cout << ret;

	return 0;
}