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
45
46
47
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>

int main()
{
	int count;
	const int maxSize = 201718;
	int money[maxSize];
	memset(&money, 0, maxSize * sizeof(int));

	std::cin >> count;

	for (int i = 0; i < count; i++)
	{
		int coin;
		std::cin >> coin;

		++money[coin - 1];
	}

	int maximum = 0;

	for (int i = 0; i < maxSize - 1; i++)
	{
		auto coinCount = money[i];

		if (coinCount > 1)
		{
			money[i + 1] += coinCount / 2;
		}

		if (money[i] > 0)
		{
			maximum = i;
		}
	}

	if (money[maxSize - 1] > 0)
	{
		maximum = maxSize - 1;
	}

	std::cout << maximum + 1;
	return 0;
}