//Krzysztof Boryczka
#pragma GCC optimize "O3"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
#define FOR(i, b, e) for(int i=b; i<=e; i++)
#define FORD(i, b, e) for(int i=b; i>=e; i--)
#define SIZE(x) ((int)x.size())
#define pb push_back
#define st first
#define nd second
#define sp ' '
#define ent '\n'
int n;
multiset<ll> s;
vector<ll> pom;
int query(ll a, ll b){
int ret=0;
while(a<b){
auto it=s.lower_bound(a);
if(it==s.begin()){
ret=-1;
break;
}
it--;
a+=*it;
pom.pb(*it);
s.erase(it);
ret++;
}
for(auto &x: pom) s.insert(x);
pom.clear();
return ret;
}
void solve(){
ll a, b;
int q, typ;
cin>>n;
FOR(i, 1, n){
cin>>a;
s.insert(a);
}
cin>>q;
FOR(i, 1, q){
cin>>typ>>a;
if(typ==1){
cin>>b;
cout<<query(a, b)<<ent;
}
if(typ==2) s.insert(a);
if(typ==3) s.erase(s.find(a));
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// int tt; cin>>tt;
// FOR(te, 1, tt)
solve();
return 0;
}
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 | //Krzysztof Boryczka #pragma GCC optimize "O3" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; const int inf=0x3f3f3f3f; const ll INF=0x3f3f3f3f3f3f3f3f; #define FOR(i, b, e) for(int i=b; i<=e; i++) #define FORD(i, b, e) for(int i=b; i>=e; i--) #define SIZE(x) ((int)x.size()) #define pb push_back #define st first #define nd second #define sp ' ' #define ent '\n' int n; multiset<ll> s; vector<ll> pom; int query(ll a, ll b){ int ret=0; while(a<b){ auto it=s.lower_bound(a); if(it==s.begin()){ ret=-1; break; } it--; a+=*it; pom.pb(*it); s.erase(it); ret++; } for(auto &x: pom) s.insert(x); pom.clear(); return ret; } void solve(){ ll a, b; int q, typ; cin>>n; FOR(i, 1, n){ cin>>a; s.insert(a); } cin>>q; FOR(i, 1, q){ cin>>typ>>a; if(typ==1){ cin>>b; cout<<query(a, b)<<ent; } if(typ==2) s.insert(a); if(typ==3) s.erase(s.find(a)); } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // int tt; cin>>tt; // FOR(te, 1, tt) solve(); return 0; } |
English