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

int main()
{
	std::array<int, 201750> tab{};
	int n, k;
	int max = 0;
	int min = 201718;
	std::cin >> n;
	for (int i = 0; i < n; i++)
	{
		std::cin >> k;
		tab[k]++;
		if (k > max)
			max = k;
		else
			if (k < min)
				min = k;
	}
	for (int i = min; i < max; i++)
	{
		tab[i + 1] += (tab[i] / 2);
	}
	while (tab[max] != 1)
	{
		tab[max + 1] += (tab[max] / 2);
		max++;
	}

	std::cout << max;
	
	return 0;
}