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 <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>

using namespace std;

const int N_MAX = 300000;

int main() {
	multiset<long long int> fishes;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		long long int w;
		scanf("%lld", &w);
		fishes.insert(w);
	}
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		int type;
		scanf("%d", &type);
		if (type == 2) {
			long long int w;
			scanf("%lld", &w);
			fishes.insert(w);
		} else if (type == 3) {
			long long int w;
			scanf("%lld", &w);
			fishes.erase(w);
		} else {
			long long int s, k;
			scanf("%lld %lld", &s, &k);
			int r = 1;
			int ile = 0;
			multiset<long long int> fishes_tmp(fishes);
			while (s < k) {
				multiset<long long int>::iterator val = fishes_tmp.upper_bound(s-1);
				if (val != fishes_tmp.begin()) --val;
				if (val == fishes_tmp.end() || *val >= s) {
					printf("-1\n");
					r = 0;
					break;
				}
				s += *val;
				fishes_tmp.erase(val);
				++ile;
			}
			if (r == 1) {
				printf("%d\n", ile);
			}
		}
	}
	return 0;
}