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

using namespace std;

multiset <long long> fish, choice;

long long sum, target;
long long sum_all;
long long a,b,x,t;
int moves;
int main(){ //naive
  int n;
  scanf("%d", &n);
  while(n--){
    scanf("%lld", &a);
    fish.insert(a);
    sum_all+=a;
  }
  int q;
  scanf("%d", &q);
  while(q--){
    scanf("%lld", &t);
    if(t==1){
      scanf("%lld %lld", &a, &b);
      if(a + sum_all < b){
        printf("-1\n");
        continue;
      }
      moves = 0;
      choice.clear();
      while(a < b){
        auto it = fish.lower_bound(a);
        if(it != fish.begin()){
          it--;
          a += (*it);
          choice.insert(*it);
          fish.erase(it);
          moves++;
        }
        else{
          printf("-1\n");
          break;
        }
      }
      if(a >= b){
        printf("%d\n", moves);
      }
      for(auto x : choice){
        fish.insert(x);
      }
    }
    else if(t==2){
      scanf("%lld", &a);
      fish.insert(a);
    }
    else if (t==3) {
      scanf("%lld", &a);
      fish.erase(a);
    }
  }
}