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

using namespace std;

int tablica[1000001];

int main()
{
	ios::sync_with_stdio(0);

	int a, b, maxx = 0;

	for (int i = 0; i < 1000001; i++)//zerowanie tablicy
	{
		tablica[i] = 0;
	}

	cin >> a;

	for (int i = 0; i < a; i++)//zbieranie informacji o monetach
	{
		cin >> b;
		tablica[b]++;
		maxx = max(maxx, b);
	}

	int i = 0;

	while (i < maxx || tablica[i] >= 2)//rozmiana
	{
		i++;
			if(tablica[i] >= 2)
			{
				tablica[i + 1] += tablica[i] / 2;
			}
	}
	cout << i;
	//cin >> a;
}