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
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 220000;
int t[MAXN];
int main() {
	int n;
	scanf("%d", &n);
	while (n--) {
		int a;
		scanf("%d", &a);
		t[a]++;
	}
	for (int i = 0; i < MAXN; i++) {
		if (t[i] > 1) {
			t[i+1] += t[i]/2;
			t[i] &= 1;
		}
	}
	for (int i = MAXN-1; i >= 0; i--) {
		if (t[i]) {
			printf("%d\n", i);
			return 0;
		}
	}
}