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

using namespace std;

long long counter[202000];

int main(int argc, char* argv[]) {
long long n, result = 0, to = 0;
scanf("%lld", &n);
long long a;
for(int i=0;i<n;i++) {
scanf("%lld", &a);
counter[a]++;
to = max(to, a);
}

result = 1;
long long number = counter[1];

while (1) {
result++;
number /= 2;
if (result<=to) number += counter[result];
if (result >= to and number == 1) break;
}

printf("%lld\n",result);
return 0;
}