結果
問題 |
No.2804 Fixer And Ratism
|
ユーザー |
|
提出日時 | 2024-07-12 22:37:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 1,031 bytes |
コンパイル時間 | 3,212 ms |
コンパイル使用メモリ | 221,100 KB |
最終ジャッジ日時 | 2025-02-22 04:39:39 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll n, q; cin >> n >> q; set<tuple<ll, ll, string>> que; map<string, ll> rs; rep(qi, q) { ll t; cin >> t; if (t == 1) { string s; ll r; cin >> s >> r; que.emplace(1, -r, s); rs[s] = r; } else if (t == 2) { ll x; cin >> x; n -= x; } else if (t == 3) { string s; ll x; cin >> s >> x; n += x; ll r = rs[s]; que.erase({1, -r, s}); que.emplace(0, -r, s); } vector<pair<ll, string>> res; while (ll(que.size()) > n) { auto [i, r, s] = *que.rbegin(); res.emplace_back(-r, s); que.erase({i, r, s}); } sort(res.begin(), res.end()); rep(i, res.size()) cout << res[i].second << '\n'; } } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }