結果
問題 | No.2804 Fixer And Ratism |
ユーザー |
![]() |
提出日時 | 2024-07-13 11:18:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,046 bytes |
コンパイル時間 | 5,181 ms |
コンパイル使用メモリ | 284,652 KB |
最終ジャッジ日時 | 2025-02-22 06:20:15 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 TLE * 3 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair<ll,ll>; using lb = long double; using T = tuple<ll, ll, ll>; #ifdef LOCAL # include <debug_print.hpp> # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast<void>(0)) #endif int main() { int n; cin >> n; int q; cin >> q; unordered_map<string, int> rate; set<string> S, T; vector<string> ans; while(q--) { int t; cin >> t; if(t==1){ string s; int r; cin >> s >> r; rate[s] = r; S.emplace(s); } else if(t==2){ int x; cin >> x; n-=x; } else{ string s; int x; cin >> s >> x; n+=x; S.erase(s); T.insert(s); } vector<pair<int,string>> vs; for(auto t : T) { vs.emplace_back(rate[t], t); } int N = n; sort(vs.rbegin(),vs.rend()); vector<pair<int, string>> tmp; for(auto [r, t] : vs) { if(N==0) { tmp.emplace_back(rate[t], t); continue; } N--; } vs.clear(); for(auto t : S) { vs.emplace_back(rate[t], t); } sort(vs.rbegin(),vs.rend()); for(auto [r, t] : vs) { if(N==0) { tmp.emplace_back(rate[t], t); continue; } N--; } sort(tmp.begin(),tmp.end()); for(auto t : tmp) { ans.push_back(t.second); if(S.count(t.second)) S.erase(t.second); if(T.count(t.second)) T.erase(t.second); } } for(auto a : ans) { cout << a << endl; } return 0; }