結果
問題 | No.2804 Fixer And Ratism |
ユーザー | eve__fuyuki |
提出日時 | 2024-07-14 17:06:34 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 1,299 bytes |
コンパイル時間 | 3,153 ms |
コンパイル使用メモリ | 232,188 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-14 17:06:41 |
合計ジャッジ時間 | 6,630 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n, q; cin >> n >> q; map<string, int> rate; set<pair<int, string>> st_fixed, st_not_fixed; for (; q--;) { int type; cin >> type; if (type == 1) { string s; int r; cin >> s >> r; rate[s] = r; st_not_fixed.insert({r, s}); if (st_fixed.size() + st_not_fixed.size() > n) { auto it = st_not_fixed.begin(); cout << it->second << "\n"; st_not_fixed.erase(it); } } else if (type == 2) { int x; cin >> x; n -= x; vector<string> removed; while (st_fixed.size() + st_not_fixed.size() > n) { if (!st_not_fixed.empty()) { auto it = st_not_fixed.begin(); removed.push_back(it->second); st_not_fixed.erase(it); } else { auto it = st_fixed.begin(); removed.push_back(it->second); st_fixed.erase(it); } } sort(removed.begin(), removed.end(), [&](string s1, string s2) { return rate[s1] < rate[s2]; }); for (string s : removed) { cout << s << "\n"; } } else { string s; int x; cin >> s >> x; n += x; if (st_not_fixed.count({rate[s], s})) { st_fixed.insert({rate[s], s}); st_not_fixed.erase({rate[s], s}); } } } }