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
36
37
38
39
40
41
42
43
44
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;


int how_many(int count, int pow) {
    while (pow > 0) {
        count /= 2;
        pow -= 1;
    }
    return count;
}


int main() {
    int n;
    scanf("%d", &n);
    vector<int> coins;
    coins.reserve(n);
    int c;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &c);
        coins.push_back(c);
    }
    sort(coins.begin(), coins.end());
    int pow = 0, count = 0;
    for (int i = 0; i < n; ++i) {
        if (coins[i] == pow) {
            count += 1;
        } else {
            count = 1 + how_many(count, coins[i] - pow);
            pow = coins[i];
        }
    }
    int max_pow = coins[n - 1], more = 0;
    while(count >= 2) {
        more += 1;
        count /= 2;
    }
    printf("%d\n", max_pow + more);

    return 0;
}