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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <vector>
#include <map>
#include <istream>
#include <sstream>

using namespace std;

vector<int> konwertuj_na_int (string s)
{
    int val;
    vector<int> vek;
    istringstream iss(s);
    while(!iss.eof())
    {
        iss >> val;
        if(val > 201718)
            return {-1};

        vek.push_back(val);
    }
    return vek;
}

int main(int argc, char *argv[])
{
    string q, w;
    getline(cin, q);
    getline (cin, w);

    int k = stoi(q);
    vector<int> tab = konwertuj_na_int(w);

    if (k != tab.size() || tab[0] == -1)
    {
        return -1;
    }

    vector<int> v;
    int wykladnik;

    for (int i = 0; i < k; ++i)
    {
        wykladnik = tab[i];
        while (wykladnik >= v.size())
        {
            v.push_back(0);
        }
        ++v[wykladnik];
    }
    for (int i = 0; i < v.size() - 1; ++i)
    {
        v[i+1]+=v[i] / 2;
    }
    int mod = v.back() / 2;
    int wynik = v.size() - 1;

    while(mod > 1)
    {
        mod = mod / 2;
        ++wynik;
    }
    if (v.back() / 2 > 0)
        ++wynik;
    return wynik;

}