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

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    vector< uint64_t> szprotki(n);

    for(int i = 0; i < n; i++)
        scanf("%llu", &szprotki[i]);

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

    int q;
    scanf("%d", &q);

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

        if(mode == 1){
            uint64_t masa, cel;
            scanf("%llu %llu", &masa, &cel);

            int cnt = 0;
            
			bool changed  = true;

            vector <uint64_t> tempSzprotki(szprotki);

            while(masa < cel && changed){
                changed = false;
                for(int j = tempSzprotki.size() - 1; j > -1; j--){
                    if(masa > tempSzprotki[j]){
                        cnt++;
                        masa += tempSzprotki[j];
                        tempSzprotki.erase(tempSzprotki.begin() + j);
                        changed = true;
                        break;
                    }
                }
            }

            if(masa >= cel) printf("%d\n", cnt);
            else printf("-1\n");
        }else if(mode == 2){
            uint64_t newFish;
            scanf("%llu", &newFish);

            int j = 0;

            while(szprotki[j] < newFish && j < (int)szprotki.size())
                j++;

            szprotki.insert(szprotki.begin() + j, newFish);
        }else{
            uint64_t fishToRemove;
            scanf("%llu", &fishToRemove);
            
            auto ftr = find(szprotki.begin(), szprotki.end(), fishToRemove);
            szprotki.erase(ftr);
        }
    }
    return 0;
}