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
43
44
45
#include <cstdio>
#include <algorithm>
using namespace std;

long long t[300000];

int main()
{
  int n;
  scanf("%d", &n);
  
  int m = 0;
  
  for (int i = 0; i < n; i++)
  {
    int a;
    scanf("%d", &a);
    m = max(a, m);
    t[a]++;
  }
  
  int ret = 0;
  for (int i = 1; i <= m; i++)
  {
    t[i] += t[i - 1] / 2;
    if (t[i])
    {
      ret = max(ret, i);
    }
  }
  
  int ret2 = 0;
  
  
  
  while (t[ret] > 1)
  {
    t[ret] /= 2;
    ret2 ++;
  }
  
  printf("%d\n", ret + ret2);
  
  return 0;
}