#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
map<long long,int> og;
map<long long,int> mapa;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,q,t,w,i;
long long a,b,x;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a;
og[a]++;
}
cin>>q;
for(i=1;i<=q;i++)
{
cin>>t>>a;
if(t==1)
{
cin>>b;
w=0;
mapa=og;
mapa[b]=0;
while(a<b)
{
w++;
auto it=mapa.lower_bound(a);
if(it==mapa.begin())
{
cout<<"-1\n";
goto bad;
}
it--;
x=(*it).fi;
a+=x;
mapa[x]--;
if(mapa[x]==0)
mapa.erase(x);
}
cout<<w<<"\n";
bad:;
}
if(t==2)
og[a]++;
if(t==3)
{
og[a]--;
if(og[a]==0)
og.erase(a);
}
}
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 | #include<bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; map<long long,int> og; map<long long,int> mapa; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,q,t,w,i; long long a,b,x; cin>>n; for(i=1;i<=n;i++) { cin>>a; og[a]++; } cin>>q; for(i=1;i<=q;i++) { cin>>t>>a; if(t==1) { cin>>b; w=0; mapa=og; mapa[b]=0; while(a<b) { w++; auto it=mapa.lower_bound(a); if(it==mapa.begin()) { cout<<"-1\n"; goto bad; } it--; x=(*it).fi; a+=x; mapa[x]--; if(mapa[x]==0) mapa.erase(x); } cout<<w<<"\n"; bad:; } if(t==2) og[a]++; if(t==3) { og[a]--; if(og[a]==0) og.erase(a); } } return 0; } |
English