結果
問題 | No.2804 Fixer And Ratism |
ユーザー | Today03 |
提出日時 | 2024-07-12 21:22:54 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 180 ms / 2,000 ms |
コード長 | 2,004 bytes |
コンパイル時間 | 3,614 ms |
コンパイル使用メモリ | 238,040 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-12 21:23:02 |
合計ジャッジ時間 | 7,766 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; int main() { int N, Q; cin >> N >> Q; map<string, int> rate; set<pair<int, string>> come, done; int nowp = N, nowh = 0; vector<string> ans; while (Q--) { int t; cin >> t; if (t == 1) { string s; int r; cin >> s >> r; rate[s] = r; come.insert({r, s}); nowh++; } else if (t == 2) { int x; cin >> x; nowp -= x; } else { string s; int r; cin >> s >> r; come.erase({rate[s], s}); done.insert({rate[s], s}); nowp += r; } if (nowp < nowh) { vector<string> cont_d, cont_c; while (cont_d.size() < nowp && done.size() > 0) { auto [r, s] = *done.rbegin(); done.erase({r, s}); cont_d.push_back(s); } while (cont_d.size() + cont_c.size() < nowp && come.size() > 0) { auto [r, s] = *come.rbegin(); come.erase({r, s}); cont_c.push_back(s); } nowh = nowp; vector<pair<int, string>> other; for (auto [r, s] : done) { other.push_back({r, s}); } for (auto [r, s] : come) { other.push_back({r, s}); } sort(other.begin(), other.end()); for (auto [r, s] : other) { ans.push_back(s); } done.clear(); come.clear(); for (string x : cont_d) { done.insert({rate[x], x}); } for (string x : cont_c) { come.insert({rate[x], x}); } } } for (string x : ans) { cout << x << endl; } }