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
#include "iostream"
#include "algorithm"
using namespace std;
int unsigned tab[201719];
int unsigned n, temp;
unsigned long long suma;
int main()
{
	scanf("%d", &n);
	for (unsigned int i = 0; i < n; i++) {
		scanf("%d", &temp);
		tab[temp]++;
	}
	int z = 201717;
	for (unsigned long long i = 0; i < z; i++) {
		tab[i+1] += tab[i] / 2;
		if (tab[i] != 0) {
			suma = i;
		}
	}
	//testowac
	if (tab[201718] != 0) {
		int a, b;
		a = tab[201718];
		while (a != 1) {
			a = a / 2;
			b++;
		}
		suma = 201717 + b;
	}
	cout << suma << endl;
	return 0;
}