#include<bits/stdc++.h>
using namespace std;
multiset<long long> s;
vector<long long> v;
set<long long>::iterator it;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int a;
cin>>a;
long long b,c,d;
for(int x=0;x<a;x++)
{
cin>>c;
s.insert(c);
}
int t;
cin>>t;
while(t--)
{
cin>>b>>c;
if(b==2)
s.insert(c);
else if(b==3)
s.erase(s.lower_bound(c));
else
{
cin>>d;
int licz=0;
while(c<d)
{
it=s.lower_bound(c);
if(it==s.begin())
{
licz=-1;
break;
}
it--;
v.push_back(*it);
// if(d==5)
// cout<<"XD"<<(*it)<<'\n';
c+=(*it);
s.erase(it);
licz++;
}
cout<<licz<<'\n';
for(auto x:v)
s.insert(x);
v.resize(0);
}
}
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 | #include<bits/stdc++.h> using namespace std; multiset<long long> s; vector<long long> v; set<long long>::iterator it; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a; cin>>a; long long b,c,d; for(int x=0;x<a;x++) { cin>>c; s.insert(c); } int t; cin>>t; while(t--) { cin>>b>>c; if(b==2) s.insert(c); else if(b==3) s.erase(s.lower_bound(c)); else { cin>>d; int licz=0; while(c<d) { it=s.lower_bound(c); if(it==s.begin()) { licz=-1; break; } it--; v.push_back(*it); // if(d==5) // cout<<"XD"<<(*it)<<'\n'; c+=(*it); s.erase(it); licz++; } cout<<licz<<'\n'; for(auto x:v) s.insert(x); v.resize(0); } } return 0; } |
English