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
36
37
38
39
40
41
42
43
44
#include <cstdio>
#include <vector>

void readCoins(std::vector<int>& coins, const int n, int& minVal, int& maxVal)
{
	int a;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a);
		if (minVal > a) minVal = a;
		if (maxVal < a) maxVal = a;
		coins[a]++;
	}
}

int changeCoins(std::vector<int>& coins, const int minVal, int& maxVal)
{
	for (int i = minVal+1; i <= maxVal; ++i) {
		coins[i] += coins[i - 1] / 2;
		coins[i - 1] %= 2;
	}

	while (coins[maxVal] != 0) {
		coins[maxVal + 1] = coins[maxVal] / 2;
		coins[maxVal] %= 2;
		maxVal++;
	}
	maxVal--;
	return maxVal;
}

int main()
{
	std::vector<int> coins(202000, 0);
	int n;
	int minCoin = 201718;
	int maxCoin = 0;

	scanf("%d", &n);
	readCoins(coins, n, minCoin, maxCoin);

	printf("%d\n", changeCoins(coins, minCoin, maxCoin));

	return 0;
}