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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <bits/stdc++.h>
using namespace std;

int n, q;
int c;
int ile = 0;
unsigned long long a;
unsigned long long b;
int odw[400000];
multiset<unsigned long long> t;
multiset<unsigned long long>::iterator it;
multiset<unsigned long long>::iterator pom;

int binarySearch( int l, int r, int x)
{
    it = t.begin();
    pom = t.begin();

    int mid = l + (r - l) / 2;
    advance(it, mid);
    advance(pom, mid-1);

    if (r >= l) {

        if (mid == 0 || (*it == x && x > *pom) )
            return mid;

        else if (*it < x)
            return binarySearch( mid+1, r, x);
        else
            return binarySearch(l, mid-1, x);
    }

    if(mid != 0)
        return mid;
    else
        return -1;
}


int main()
{

scanf("%d", &n);
for(int i = 0; i < n; ++i){
    scanf("%lld", &a);
    t.insert(a);
}


scanf("%d", &q);
for(int i = 1; i <= q; ++i){
    scanf("%d", &c);
    ile = 0;
    if(c == 2){
        scanf("%lld", &a);
        t.insert(a);

    }
    else if(c == 3){
        scanf("%lld", &a);
        it = t.find( a);
        odw[distance(t.begin(), it)] = -1;
        //t.erase( it);
    }
    else{
        scanf("%lld%lld", &a, &b );
        while(a < b){

            int mx = binarySearch( 0, t.size()-1, a);
            //cout<<mx<<endl;
            for(int j = mx-1; j >=0; j--){
                if(odw[j] != i && odw[j] != -1){
                     it = t.begin();
                    advance(it, j);
                    a+=*it;
                   // cout<<*it<<"GG"<<endl;
                    ile++;
                    odw[j]= i;
                    break;
                }
                else if(j == 0 && odw[j] == i){
                    ile = -1;
                    a = b;
                }
            }

        }


    printf("%d\n", ile);
    }
}
    return 0;
}