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

using namespace std;

int n;

const int MAXMONETY = 260000;

vector<int> nom(MAXMONETY, 0);
int maxnom = 0;


int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        int k;
        scanf("%d", &k);

        nom[k]++;
        maxnom = max(maxnom, k);
    }

    bool c = true;

    for(int i = 0; (i <= maxnom) || c; i++)
    {
        nom[i+1] += nom[i]/2;
        if(nom[i+1] == 0)
        {
            if(i > maxnom)
                c = false;
        }
        else maxnom = max(maxnom, i+1);

    }

    printf("%d", maxnom);

    return 0;
}