1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdio>

int N, score;
int A[300000];

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

   int in;
   for (int i = 0; i < N; ++i) {
      scanf("%d", &in);
      ++A[in];
   }

   for (int i = 0; i < 270000; ++i) {
      A[i+1] += A[i] / 2;
      A[i] %= 2;
      if (A[i] > 0) {
         score = i;
      }
   }

   printf("%d\n", score);
}