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
#include <bits/stdc++.h>
using namespace std;
const int MAX = 300000;
int T[MAX];

int main() {
	ios_base::sync_with_stdio(false);
	
	int a, n, last;
	cin >> n;
	
	fill_n(T, MAX, 0);
	
	for(int i = 1; i <= n; i++) {
		cin >> a;
		last = max(last, a);
		T[a]++;
	}
	
	for(int i = 0; i < MAX - 1; i++) {
		T[i + 1] += T[i] / 2;
		if(T[i + 1]) last = i + 1;
	}
	
	cout << last << endl;
	
	return 0;
}