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
#include <bits/stdc++.h>
#define QCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr<<#x<<" "<<x<<endl
#define LL unsigned long long
using namespace std;

int n,q, op, res;
LL w, l, r, s, k, y;
multiset <LL> S, SS;
int main(){
	QCK;
	cin>>n;
	while(n--){
		cin>>w;
		S.insert(w);
	}
	cin>>q;
	while(q--){
		cin>>op;
		if(op==1){
			cin>>s>>k;
			res=0;
			while(s<k){
				auto it = lower_bound(S.begin(),S.end(), s);
				//debug(*it);
				if(it==S.begin()){
					res=-1;
					break;
				}
				else{
					res++;
					it--;
					y=*it;
					s+=y;
					SS.insert(y);
					S.erase(it);
				}
			}
			
			for(auto it : SS)
						S.insert(it);
					SS.clear();
			
			cout<<res<<endl;
		}
		
		else{
			cin>>w;
			if (op==2) S.insert(w);
			else S.erase(w);
		}
		
	}

}