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

using namespace std;

const int MAX = 201718;

int main()
{
	int n;
	int a;
	array<int, MAX + 1> A = {};

	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		A[a]++;
	}

	int res = 0;

	for (int i = 0; i < MAX; i++)
	{
		if (A[i] > 0)
		{
			res = i;
			A[i + 1] += A[i] / 2;
		}
	}

	if (A[MAX] > 0)
	{
		res = MAX;

		while (A[MAX] > 1)
		{
			res++;
			A[MAX] /= 2;
		}
	}

	cout << res;

	return 0;
}