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

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	multiset <long long> ryba;
	int a;
	cin >> n;
	for (int i=0;i<n;i++) {
		cin >> a;
		ryba.emplace(a);
	}
//	for(auto u:ryba) 
//		cout << u << " ";
//	cout << endl;
	int q;
	cin >> q;
	for (int i=0;i<q;i++) {
		multiset <long long> temp = ryba;
		int kom;
		cin >> kom;
		if (kom == 1) {
			int w,m,wyn=0;
			cin >> w >> m;
			bool kon = false;
			multiset<long long>::iterator up;
			bool pierw = true;
			while (w<m) {
				if (temp.empty()) {
					kon = true;
					break;
				}
				//if (!pierw && ++up != temp.end() && *(++up) >= w) {}
				//else {
					up = temp.lower_bound(w);
				//}
				if (up == temp.begin()) {
					kon = true;
					break;
				}
				--up;
				if (*up == w)
					--up;
			//	cout << ">>> " << *up << " <<<" << endl;
				w+=(*up);
				temp.erase(up);
				wyn++;
				pierw = false;
			}
			if (kon) {
				cout << -1 << endl;
			}
			else {
				cout << wyn << endl;
			}
		}
		if (kom == 2) {
			int masa;
			cin >> masa;
			ryba.emplace(masa);
		}
		if (kom == 3) {
			int masa;
			cin >> masa;
			ryba.erase(ryba.find(masa));
		}
	}
}