#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector <long long> r;
for (int i=0; i<n;i++){
long long tmp;
cin >> tmp;
r.push_back(tmp);
}
sort(r.begin(),r.end());
int q;
cin >> q;
vector <long long> rr;
rr=r;
for (int q2=0;q2<q;q2++){
int typ;
cin >> typ;
if (typ==1){
long long a,b;
cin >> a >> b;
map<long long,int>ryb;
for (int i=0; i<rr.size();i++){
ryb[rr[i]]++;
}
long long suma=a;
int wynik=0;
while (suma<b){
//cout << "owo"<<endl;
auto tmp = ryb.lower_bound(suma);
//cout << suma<<" "<<b<<endl<<endl;
if (!ryb.empty()){
/*for (auto i=ryb.begin();i!=ryb.end();i++){
cout << (i->first)<<" "<<i->second<<endl;
}*/
if (tmp==ryb.end()){
tmp--;
}else if (tmp->first != ryb.begin()->first ){
tmp--;
}
/*cout <<"owo "<< tmp->first<<endl;
cout<<tmp->first<<endl;
cout << endl;*/
if (suma>ryb.begin()->first){
ryb[tmp->first]--;
/*for (auto i=ryb.begin();i!=ryb.end();i++){
cout << (i->first)<<" "<<i->second<<endl;
}*/
if (ryb[tmp->first]==0){
ryb.erase(tmp->first);
}
suma+=tmp->first;
wynik++;
if (ryb.empty() && suma>= b){
break;
}
if (ryb.empty()){
wynik=-1;
break;
}
}else{
wynik=-1;
break;
}
}else{
wynik=-1;
break;
}
}
cout << wynik<<endl;
}
if (typ==2){
long long a;
cin >> a;
rr.push_back(a);
sort(rr.begin(),rr.end());
}
if (typ==3){
long long a;
cin >> a;
auto wyn=lower_bound(rr.begin(),rr.end(),a);
rr.erase(wyn);
}
}
}
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 <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector <long long> r; for (int i=0; i<n;i++){ long long tmp; cin >> tmp; r.push_back(tmp); } sort(r.begin(),r.end()); int q; cin >> q; vector <long long> rr; rr=r; for (int q2=0;q2<q;q2++){ int typ; cin >> typ; if (typ==1){ long long a,b; cin >> a >> b; map<long long,int>ryb; for (int i=0; i<rr.size();i++){ ryb[rr[i]]++; } long long suma=a; int wynik=0; while (suma<b){ //cout << "owo"<<endl; auto tmp = ryb.lower_bound(suma); //cout << suma<<" "<<b<<endl<<endl; if (!ryb.empty()){ /*for (auto i=ryb.begin();i!=ryb.end();i++){ cout << (i->first)<<" "<<i->second<<endl; }*/ if (tmp==ryb.end()){ tmp--; }else if (tmp->first != ryb.begin()->first ){ tmp--; } /*cout <<"owo "<< tmp->first<<endl; cout<<tmp->first<<endl; cout << endl;*/ if (suma>ryb.begin()->first){ ryb[tmp->first]--; /*for (auto i=ryb.begin();i!=ryb.end();i++){ cout << (i->first)<<" "<<i->second<<endl; }*/ if (ryb[tmp->first]==0){ ryb.erase(tmp->first); } suma+=tmp->first; wynik++; if (ryb.empty() && suma>= b){ break; } if (ryb.empty()){ wynik=-1; break; } }else{ wynik=-1; break; } }else{ wynik=-1; break; } } cout << wynik<<endl; } if (typ==2){ long long a; cin >> a; rr.push_back(a); sort(rr.begin(),rr.end()); } if (typ==3){ long long a; cin >> a; auto wyn=lower_bound(rr.begin(),rr.end(),a); rr.erase(wyn); } } } |
English