1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdio>
#include <algorithm>
const int maxSize = 1<<18; //201718;
int boxes[maxSize];

int main()
{
   int n, coin, maxCoin=0;
   scanf("%d", &n);
   for(int i=0; i<n; i++) {
     scanf("%d", &coin);
     boxes[coin]++;
     if(coin > maxCoin) maxCoin = coin;
   }
   for(int i=1; i<maxSize; i++) {
     if(boxes[i]>0) {
       boxes[i+1] += (boxes[i]/2);
       boxes[i] = boxes[i]%2;
       if(i>maxCoin) maxCoin = i;
     }
   }
   printf("%d\n", maxCoin);
}