// #include // Temp fix for gcc13 global pragma // #pragma GCC target("avx2,bmi2,popcnt,lzcnt") // #pragma GCC optimize("O3,unroll-loops") #include // #include 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 contributed; map> name_by_rating; vector res; for(auto qi = 0; qi < qn; ++ qi){ int type; cin >> type; if(type == 1){ string name; int r; cin >> name >> r; name_by_rating[r] = name; } else if(type == 2){ int x; cin >> x; computer -= x; } else{ string s; int x; cin >> s >> x; contributed.insert(s); computer += x; } static vector> left; left.clear(); int rem = computer; for(auto [r, s]: name_by_rating){ if(contributed.contains(s)){ if(!rem){ left.push_back({r, s}); } else{ -- rem; } } } for(auto [r, s]: name_by_rating){ if(!contributed.contains(s)){ if(!rem){ left.push_back({r, s}); } else{ -- rem; } } } for(auto [r, s]: left | ranges::views::reverse){ name_by_rating.erase(r); res.push_back(s); } } ranges::copy(res, ostream_iterator(cout, "\n")); return 0; } /* */