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
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>

#include <algorithm>

#include <vector>

#include <math.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n, Max_Nomin, ilosc;
	cin >> n;
	vector <int> wej;
	
	for (int i=0; i<n; i++)
	{
		int b;
		cin >> b;
		wej.push_back(b);
	}
	
	sort (wej.begin(), wej.end());
	//cout << wej[0];
	Max_Nomin = wej[wej.size()-1];
	ilosc = pow(2, Max_Nomin-wej[wej.size()-2]);
	
	for (int i=wej.size()-2; i>=0; i--)
	{
		int Prev = wej[i+1];
		int Now = wej[i];
		int j=0;
		
		while (Now==wej[i] && j<ilosc && i!=0)
		{
			j++;
			i--;
		}
		i++;
		if (ilosc==j)
		{
			
		//	cout << wej[i] << endl;
			Max_Nomin++;
			ilosc = pow(2, Max_Nomin-wej[i-1]);
		}
		else
		{
			ilosc -= j;
			ilosc *= pow(2, Now-wej[i-1]);
		}
		
		
		
	}
	cout << Max_Nomin;
}