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
#include <iostream>
#include <cstring>

int main()
{
	const int size = 201718+21;
	int count;
	int value;
	std::cin >> count;
	int* moneyArray = new int[size];

	memset(moneyArray, 0, size*sizeof(int));

	for (int i = 0; i < count; i++)
	{
		std::cin >> value;
		moneyArray[value]++;
	}

	int lastValidIdx = 0;
	for (int i = 1; i < size; i++)
	{
		moneyArray[i] += (int)(moneyArray[i - 1] / 2);
		if (moneyArray[i] != 0)
			lastValidIdx = i;
	}

	std::cout << lastValidIdx << std::endl;
	return 0;
}