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
#include <cstdio>
#include <set>
int main ()
{
  int n, t, i;
  long long w, k;
  std::multiset <long long> W;
  scanf ("%d", &n);
  while (n--)
  {
    scanf ("%lld", &w);
    W.insert (-w);
  }
  scanf ("%d", &n);
  while (n--)
  {
    scanf ("%d%lld", &t, &w);
    switch (t)
    {
      case 1:
      scanf ("%lld", &k);
      i = 0;
      for (auto V=W; w < k; i++)
      {
        auto j=V.upper_bound (-w);
        if (j==V.end ()) break;
        w -= *j;
        V.erase(j);
      }
      printf ("%d\n", w < k? -1: i);
      break;
      case 2:
      W.insert (-w);
      break;
      case 3:
      W.erase (W.find (-w));
    }
  }
  return 0;
}