結果
問題 | No.2804 Fixer And Ratism |
ユーザー |
|
提出日時 | 2024-07-12 22:37:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 1,337 bytes |
コンパイル時間 | 2,115 ms |
コンパイル使用メモリ | 184,552 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-12 22:37:38 |
合計ジャッジ時間 | 4,257 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #include "algo/debug.h" #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long void solve() { int n, q; cin >> n >> q; set<pair<int, string>> spec, nor; map<string, int> rat; while (q--) { int op; cin >> op; if (op == 1) { string s; int r; cin >> s >> r; nor.insert({r, s}); rat[s] = r; } else if (op == 2) { int x; cin >> x; n -= x; } else { string s; int x; cin >> s >> x; n += x; auto it = (nor.find({rat[s], s})); if (it != nor.end()) { nor.erase(it); } spec.insert({rat[s], s}); } n = min(n, (int)1e9); set<pair<int, string>> ans; while (nor.size() + spec.size() > n) { if (nor.size()) { ans.insert(*nor.begin()); nor.erase(nor.begin()); } else if (spec.size()) { ans.insert(*spec.begin()); spec.erase(spec.begin()); } } for (auto &x : ans) { cout << x.second << "\n"; } } } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { solve(); } // cerr << "Time elapsed: " << ((long double)clock() / CLOCKS_PER_SEC) << " s.\n"; }