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
#include <cstdio>
#include <cstdlib>
using namespace std;

#define MAX_A 300000
int n;
int s[MAX_A];

int main() {
    int i;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        s[a]++;
    }
    for (i = 0; i < MAX_A-1; i++) {
        s[i+1] += s[i]/2;
    }
    for (i = MAX_A-1; i >= 0; i--) {
        if (s[i] > 0) {
            printf("%d\n", i);
            return 0;
        }
    }
    return -1;
}