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

int main()
{
  long long n;

  std::cin >> n;

  std::vector<long long> w, wt;
  long long wx;
  for (long long i=0;i<n;i++)
  {
    std::cin >> wx;
    wt.push_back(wx);
  }
  std::sort(wt.begin(), wt.end());
  long long q;
  long long s, k;
  std::cin >> q;

  for (long long i=0;i<q;i++)
  {
    w = wt;
    long long type;
    std::cin >> type;
    long long l(0);
    switch(type){
      case 1:
        std::cin >> s >> k;
        while(s<k){
          std::vector<long long>::iterator it = std::find_if(w.begin(), w.end(), [&](const auto& e){return e >= s;});
          if ((it==w.end() && *(it-1) >= s )|| it==w.begin()){
            break;
          }
          l++;
          s+=*(it-1);
          w.erase(it-1);
        }
        if (s<k){
          std::cout << -1 << std::endl;
        }
        else {
          std::cout << l << std::endl;
        }
        break;
      case 2:       
        std::cin >> wx;
        wt.push_back(wx);
        std::sort(wt.begin(), wt.end());
        break;
      default:
        std::cin >> wx;
        std::vector<long long>::iterator it=std::find(wt.begin(), wt.end(), wx);
        if (it!=wt.end()) wt.erase(it);
    }
  }
  return 0;
}