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
#include <iostream>

using namespace std;

const int MAXA = 201800;

int coins[MAXA];

int main()
{
    int n;
    scanf("%d", &n);

    int max_nominal = 0;
    while (n--) {
        int a;
        scanf("%d", &a);
        coins[a]++;
        max_nominal = max(max_nominal, a);
    }

    int i = 0;
    while (i <= max_nominal) {
        coins[i + 1] += coins[i] / 2;
        if (coins[max_nominal + 1] > 0) {
            max_nominal++;
        }
        i++;
    }
    printf("%d\n", max_nominal);

    return 0;
}