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
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

vector <long long> fishes;
long long x,y,z,mass;
int n,m,op,mid;
long long result;
long long pp,mm,kk;
bool possible;

int binsearch(long long val){
    int p=0;
    int k=fishes.size()-2;
    int mid=(p+k)/2;
    while(val<fishes[mid]||val>fishes[mid+1]){
        if(val<fishes[mid]){
            k=mid;
            mid=(p+k)/2;
        }
        else{
            p=mid;
            mid=(p+k+1)/2;
        }
    }
    return mid;
}

int main()
{
    scanf("%d",&n);
    fishes.push_back(-1);
    for(int i=0;i<n;i++){
        scanf("%ld",&z);
        fishes.push_back(z);
    }
    fishes.push_back(1000000000001);

    sort(fishes.begin(),fishes.end());

    scanf("%d",&m);

    for(int i=0;i<m;i++){
        scanf("%d",&op);

        if(op==1){
            scanf("%lld%lld",&x,&y);
            result=0;
            possible=0;
            while(x<y){
                vector <long long> new_v(fishes);
                pp=0;
                kk=fishes.size()-2;
                mm=(pp+kk)/2;
                while(new_v[mm]>=x||new_v[mm+1]<x){
                    if(new_v[mm]>=x){
                        kk=mm;
                        mm=(pp+kk)/2;
                    }
                    else{
                        pp=mm;
                        mm=(pp+kk+1)/2;
                    }
                }
                if(mm==0) {printf("-1\n");possible=1;break;}
                else{
                    result++;
                    x+=fishes[mm];
                    new_v.erase(new_v.begin()+mm+1);
                }
            }
            if(!possible) printf("%lld\n",result);
        }
        else if(op==2){
            scanf("%lld",&mass);
            fishes.insert(fishes.begin()+binsearch(mass)+1,mass);
        }
        else if(op==3){
            scanf("%lld",&mass);
            fishes.erase(fishes.begin()+binsearch(mass)+1);
        }
    }

    return 0;
}