#include <bits/stdc++.h>
using namespace std;
multiset<long long> ryby;
queue<long long> zje;
int main()
{
long long n,a,b,c,h,l;
scanf("%lld", &n);
for(int i=0; i<n; i++){
scanf("%lld", &a);
ryby.insert(-a);
//cout<<-a<<endl;
}
//ryby.erase(ryby.lower_bound(-1));
//for (multiset<int>::iterator it=ryby.begin(); it!=ryby.end(); ++it)
//cout << ' ' << *it;
//cout << '\n';
scanf("%lld", &n);
for(int i=0; i<n; i++){
scanf("%lld", &a);
if(a==2){
scanf("%lld", &b);
ryby.insert(-b);
//cout<<-b<<endl;
}else if(a==3){
scanf("%lld", &b);
ryby.erase(ryby.lower_bound(-b));
}else{
scanf("%lld%lld", &b, &c);
//cout<<"RYBY "<<ryby.size()<<endl;
l=0;
while(b<c&&!ryby.empty()){
l++;
h=*ryby.upper_bound(-b);
if(h>=0){
break;
}
//cout<<" "<<h<<" ";
b-=h;
//cout<<b<<endl;
ryby.erase(ryby.lower_bound(h));
zje.push(h);
}
if(b>=c){
printf("%lld\n", l);
}else{
printf("-1\n");
}
while(!zje.empty()){
ryby.insert(zje.front());
zje.pop();
}
}
}
}
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 | #include <bits/stdc++.h> using namespace std; multiset<long long> ryby; queue<long long> zje; int main() { long long n,a,b,c,h,l; scanf("%lld", &n); for(int i=0; i<n; i++){ scanf("%lld", &a); ryby.insert(-a); //cout<<-a<<endl; } //ryby.erase(ryby.lower_bound(-1)); //for (multiset<int>::iterator it=ryby.begin(); it!=ryby.end(); ++it) //cout << ' ' << *it; //cout << '\n'; scanf("%lld", &n); for(int i=0; i<n; i++){ scanf("%lld", &a); if(a==2){ scanf("%lld", &b); ryby.insert(-b); //cout<<-b<<endl; }else if(a==3){ scanf("%lld", &b); ryby.erase(ryby.lower_bound(-b)); }else{ scanf("%lld%lld", &b, &c); //cout<<"RYBY "<<ryby.size()<<endl; l=0; while(b<c&&!ryby.empty()){ l++; h=*ryby.upper_bound(-b); if(h>=0){ break; } //cout<<" "<<h<<" "; b-=h; //cout<<b<<endl; ryby.erase(ryby.lower_bound(h)); zje.push(h); } if(b>=c){ printf("%lld\n", l); }else{ printf("-1\n"); } while(!zje.empty()){ ryby.insert(zje.front()); zje.pop(); } } } } |
English