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 <cstdio>
#include <cstdlib>
#include <algorithm>

int main(){
    int n;
    scanf("%d",&n);
	int rozmiar = 201718+log2(n)+2;
    int* sum = new int[rozmiar];
    int* tab = new int[n];
    for(int i=0;i<rozmiar;i++){
		sum[i]=0;
	}
    for(int i=0;i<n;i++){
        scanf("%d",&tab[i]);
        sum[tab[i]]+=1;
    }
	int result = 0;
	int i =0;
	while(i<rozmiar){
		if(sum[i]!=0 && sum[i]!=1){
			sum[i+1] +=sum[i]/2;
			sum[i] = (sum[i]%2)?1:0;
		}
		result = (sum[i]!=0)?i:result;
		i++;
	}
	printf("%d\n",result);
	delete tab;
	delete sum;
}

//Author: Helena Borak