// #include <bits/allocator.h> // Temp fix for gcc13 global pragma // #pragma GCC target("avx2,bmi2,popcnt,lzcnt") // #pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> // #include <x86intrin.h> using namespace std; #if __cplusplus >= 202002L using namespace numbers; #endif #ifdef LOCAL #include "Debug.h" #else #define debug_endl() 42 #define debug(...) 42 #define debug2(...) 42 #define debugbin(...) 42 #endif int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int computer, qn; cin >> computer >> qn; set<string> did_contribute, left; map<string, int> rating_of; vector<pair<int, string>> contributed; vector<pair<int, string>> useless; vector<string> res; for(auto qi = 0; qi < qn; ++ qi){ int type; cin >> type; if(type == 1){ string name; int r; cin >> name >> r; rating_of[name] = r; useless.insert(partition_point(useless.begin(), useless.end(), [&](auto &x){ return x.first > r; }), pair{r, name}); } else if(type == 2){ int x; cin >> x; computer -= x; assert(computer >= 1); } else{ string name; int x; cin >> name >> x; computer += x; assert(!left.contains(name)); if(!did_contribute.contains(name)){ did_contribute.insert(name); int r = rating_of[name]; useless.erase(partition_point(useless.begin(), useless.end(), [&](auto &x){ return x.first > r; })); contributed.insert(partition_point(contributed.begin(), contributed.end(), [&](auto &x){ return x.first > r; }), pair{r, name}); } } if((int)contributed.size() + (int)useless.size() <= computer){ continue; } if((int)contributed.size() <= computer){ int size = min((int)useless.size(), computer - (int)contributed.size()); while((int)useless.size() > size){ res.push_back(useless.back().second); useless.pop_back(); left.insert(res.back()); } } else{ while((int)contributed.size() > computer || !useless.empty()){ if(useless.empty() || (int)contributed.size() > computer && contributed.back().first < useless.back().first){ res.push_back(contributed.back().second); contributed.pop_back(); } else{ res.push_back(useless.back().second); useless.pop_back(); } left.insert(res.back()); } } } ranges::copy(res, ostream_iterator<string>(cout, "\n")); return 0; } /* */