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
34
35
36
37
38
39
40
41
42
#include "cstdio"
#include "algorithm"
#include "vector"
#include "cmath"
using namespace std;
long long n, x, cnt[202005], k, tmp, power[21], res;
int main()
{
  for (int i = 0, r = 1; i < 21; i++, r *= 2)
  {
    power[i] = r;
  }

  scanf ("%lld", &n);
  while (n--)
  {
    scanf ("%lld", &x);
    cnt[x]++;
  }

  for (int i = 1; i < 202000; i++)
  {
    if (cnt[i] == 0)
    {
      continue;
    }
    else
    {
      res = i;
    }
    k = cnt[i];
    while (k > 1)
    {
      cnt[i + (int)log2(k)]++;
      k -= power[(int)log2(k)];
    }
  }

  printf ("%lld\n", res);

  return 0;
}