#include <cstdio>
#include <set>
#include <vector>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define VAR(v,w) __typeof(w) v=(w)
#define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)
#define PB push_back
#define SIZE(c) ((int)(c).size())
#define INT(x) int x; scanf("%d", &x)
#define LLG(x) LL x; scanf("%lld", &x)
typedef long long LL;
typedef vector<LL> VLL;
int main() {
INT(n);
multiset<LL> ss;
REP(i,n) {
LLG(w);
ss.insert(w);
}
INT(q);
REP(qq,q) {
INT(t);
switch (t) {
case 1: {
LLG(s);
LLG(k);
VLL e;
while (s < k) {
VAR(it,ss.lower_bound(s));
if (it == ss.begin()) break;
--it;
s += *it;
e.PB(*it);
ss.erase(it);
}
printf("%d\n", s >= k ? SIZE(e) : -1);
FORE(it,e) ss.insert(*it);
break;
}
case 2: {
LLG(w);
ss.insert(w);
break;
}
case 3: {
LLG(w);
ss.erase(ss.find(w));
break;
}
default:
break;
}
}
}
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 | #include <cstdio> #include <set> #include <vector> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define VAR(v,w) __typeof(w) v=(w) #define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it) #define PB push_back #define SIZE(c) ((int)(c).size()) #define INT(x) int x; scanf("%d", &x) #define LLG(x) LL x; scanf("%lld", &x) typedef long long LL; typedef vector<LL> VLL; int main() { INT(n); multiset<LL> ss; REP(i,n) { LLG(w); ss.insert(w); } INT(q); REP(qq,q) { INT(t); switch (t) { case 1: { LLG(s); LLG(k); VLL e; while (s < k) { VAR(it,ss.lower_bound(s)); if (it == ss.begin()) break; --it; s += *it; e.PB(*it); ss.erase(it); } printf("%d\n", s >= k ? SIZE(e) : -1); FORE(it,e) ss.insert(*it); break; } case 2: { LLG(w); ss.insert(w); break; } case 3: { LLG(w); ss.erase(ss.find(w)); break; } default: break; } } } |
English