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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>

#define DEBUG if(0)
#define COUT cout << "\e[36m"
#define ENDL "\e[39m" << endl
#define VAR(v) " [\e[32m" << #v << "\e[36m=\e[91m" << v << "\e[36m] "

using  namespace std;
typedef long long LL;

int n;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    multiset<LL> fishset;

    for (int i = 0; i < n; ++i)
    {
        LL a;
        cin >> a;
        fishset.insert(a);
    }
    int q;
    cin >> q;
    while(q--)
    {
        DEBUG for(auto el : fishset)
            COUT << el << " ";
        DEBUG COUT << ENDL;
        int type;
        cin >> type;
        if(type == 1) /// SZCZUPAK ATTACK!
        {
            long long smass, kmass;
            cin >> smass >> kmass;
            DEBUG COUT << "ATTACK" << VAR(smass) << VAR(kmass) << ENDL;
            vector<LL> removed;
            while(1)
            {
                if(smass >= kmass)
                {
                    cout << removed.size() << "\n";
                    break;
                }
                set<LL>::iterator lowerb = fishset.lower_bound(smass);
                if(lowerb == fishset.begin())
                {
                    cout << "-1\n";
                    break;
                }
                //DEBUG COUT << "\t" << VAR(*lowerb) << ENDL;
                --lowerb;
                DEBUG COUT << "\t" << VAR(*lowerb) << ENDL;
                smass += *lowerb;
                removed.push_back(*lowerb);
                fishset.erase(lowerb);

            }
            while(!removed.empty())
            {
                fishset.insert(removed.back());
                removed.pop_back();
            }
        }
        else if(type == 2) ///SZPROTA ADD!
        {
            int mass;
            cin >> mass;
            DEBUG COUT << "ADD" << VAR(mass) << ENDL;
            fishset.insert(mass);
        }
        else if(type == 3) ///SZPROTA REMOVE!
        {
            int mass;
            cin >> mass;
            DEBUG COUT << "REMOVE" << VAR(mass) << ENDL;
            fishset.erase(fishset.find(mass));
        }

    }

    return 0;
}