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

using namespace std;
#define ll long long
#define st first
#define nd second 

map<ll,int> mapa;
map<ll,int>::iterator it;

vector<ll> wziete;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		ll x;
		cin >> x;
		mapa[-x]++;
	}
	int q;
	cin >> q;
	while(q--){
		int nr;
		cin >> nr;
		if(nr == 1){
			ll s,k;
			cin >> s >> k;
			if(k <= s){
				cout << 0 << '\n';
				continue;
			}
			int ans = 0;
			ll temp = s;
			while(temp < k){
				it = mapa.lower_bound(-(temp - 1));
				if(it == mapa.end())
					break;
				ll nb = it -> st;
				temp += -nb;
				wziete.push_back(nb);
				if(it -> nd == 1)
					mapa.erase(nb);
				else
					it -> nd--;
				ans++;
			}
			if(temp < k)
				cout << -1 << '\n';
			else
				cout << ans << '\n';
			for(int i = 0; i < (int) wziete.size(); i++)
				mapa[wziete[i]]++;
			wziete.clear();
			continue;
		}
		ll w;
		cin >> w;
		if(nr == 2)
			mapa[-w]++;
		else{
			if(mapa[-w] == 1)
				mapa.erase(-w);
			else
				mapa[-w]--;
		}
	}
	
	return 0;
}