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
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 1000007
int t[MAXN];

int main() {
    int n;
    scanf("%d" ,&n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &t[i]);
    }
    sort(t, t + n);
    int potega = 0, ile = 0, max_pot = 0;
    for (int i = 0; i < n; i++) {
        int nowa_pot = t[i];
        while (potega < nowa_pot) {
            if (ile > 0) {
                max_pot = max(max_pot, potega);
            }
            ile /= 2;
            potega++;
        }
        ile++;
        max_pot = max(max_pot, potega);
    }
    while (ile > 0) {
        max_pot = max(max_pot, potega);
        ile /= 2;
        potega++;
    }
    printf("%d\n", max_pot);
    return 0;
}