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

using namespace std;

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

    constexpr auto SIZE=500000;
    int tab[SIZE];
    for (int i=0;i<SIZE;i++){
        tab[i]=0;
    }
    for (int i=0;i<N;i++){
        int an;
        scanf("%d", &an);

        tab[an]++;
    }

    for (int i=0;i<SIZE;i++){
       tab[i+1] += tab[i]/2;
    }

    for (int i=SIZE-1;i>=0;i--){
        if (tab[i] != 0){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}