#include <bits/stdc++.h> using namespace std; int main() { int a, typ, j, d, c; cin >> a; vector <int> v; for(int b = 0; b < a; ++b) { cin >> c; v.push_back(c); } cin >> c; vector <int> g; for(int b = 0, x, y; b < c; ++b) { cin >> typ >> j; if(typ == 1) { cin >> d; for(x = 0, y = 0; x < a; ++x) { if(j >= d) break; if(j > v[x]) { j += v[x]; ++y; } if(x == a - 1 && j < d) y = -1; } g.push_back(y); }else if(typ == 2) { v.push_back(j); }else { for(x = 0;x < a; ++x) { if(j == v[x]) v.erase(v.begin()+x); } } a = v.size(); } int z = g.size(); for(int b = 0; b < z; ++b) cout << v[b] << endl; 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 | #include <bits/stdc++.h> using namespace std; int main() { int a, typ, j, d, c; cin >> a; vector <int> v; for(int b = 0; b < a; ++b) { cin >> c; v.push_back(c); } cin >> c; vector <int> g; for(int b = 0, x, y; b < c; ++b) { cin >> typ >> j; if(typ == 1) { cin >> d; for(x = 0, y = 0; x < a; ++x) { if(j >= d) break; if(j > v[x]) { j += v[x]; ++y; } if(x == a - 1 && j < d) y = -1; } g.push_back(y); }else if(typ == 2) { v.push_back(j); }else { for(x = 0;x < a; ++x) { if(j == v[x]) v.erase(v.begin()+x); } } a = v.size(); } int z = g.size(); for(int b = 0; b < z; ++b) cout << v[b] << endl; return 0; } |