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
#include <iostream>
#include <algorithm>

using namespace std;

int a[201719+32];

int main()
{
  int n, b, c = 0;

  cin >> n;
  for(int i=0; i<n; i++)
  {
    cin >> b;
    c = max(b, c);
    a[b]++;
  }

  int j = a[0];
  int k = 0;
  int i = 1;
  while(i <= c || j > 0)
  {
    j = j / 2 + a[i];
    k = (j != 0) ? i : k;
    i ++;
  }
  cout << k;
  return 0;
}