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
#include <bits/stdc++.h>
using namespace std;

multiset < long long >foreating;
//multiset < long long > :: iterator lasteaten;
multiset < long long > :: iterator lower;

int eat(long long s, long long k, int result){
    //lower=--foreating.lower_bound(s);
    //cout << "hjhj " << *lower << endl;
    if(s>=k)return result;
    else if(foreating.lower_bound(s)!=foreating.begin()){
        lower=--foreating.lower_bound(s);
        //cout << "dhjkwfk " << *lower << endl;
        result++;
        s+=*lower;
        foreating.erase(lower);
        return eat(s,k,result);
    }
    else return -1;
}

int main(){
    multiset < long long >fish;
    int n,q,result;
    long long s,k,w,m;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> m;
        fish.insert(m);
    }
    cin >> q;
    for(int i=0;i<q;i++){
        cin >> m;
        if(m==1){
            cin >> s >> k;
            result=0;
            //lasteaten = --fish.begin();
            foreating=fish;
            cout << eat(s,k,result) << endl;
        }
        else if(m==2){
            cin >> w;
            fish.insert(w);
        }
        else{
            cin >> w;
            fish.erase(fish.find(w));
        }
    }
    /*cout << endl << endl;
    while(!fish.empty()){
        cout << *fish.begin() << " ";
        fish.erase(fish.begin());
    }*/
}