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

long i, n, m, t;
long a[201800] = {0};

int main()
{
  scanf("%ld", &n);
  m = 0;
  for(int i = 0; i < n; i++)
  {
    scanf("%ld", &t);
    a[t]++;
    if (m < t)
      m = t;
  }

  for(int i = 0; i <= m; i++)
    a[i + 1] += a[i] >> 1;
 
  while (a[m + 1] > 0)
  {
    m++;
    a[m + 1] += a[m] >> 1;
  }

  printf("%ld", m);
}