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
#include "iostream"
#include "new"
int main(void) 
{
    int n, carr, i, tmp, min, max, res, arr[201720];
    min = 201720;
    max = 0;
    carr = 0;
    std::cin >> n;
    for ( int i=0; i<n; ++i ){
	std::cin>>tmp;
	arr[tmp]++;
	if (tmp > max)
	    max = tmp;
	if (tmp < min)
	    min = tmp;
    }
    for ( int i=min; i<max+1; ++i ){
	carr = (carr+arr[i]) >> 1;
    }
    while(carr > 0){
	max++;
	carr = carr >> 1;
    }
    std::cout << max << "\n";
    return 0;
}