結果

問題 No.2804 Fixer And Ratism
ユーザー Today03Today03
提出日時 2024-07-12 21:22:54
言語 C++17
(gcc 12.3.0 + boost 1.83.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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 4 ms
6,944 KB
testcase_03 AC 43 ms
6,940 KB
testcase_04 AC 28 ms
6,944 KB
testcase_05 AC 12 ms
6,944 KB
testcase_06 AC 109 ms
6,944 KB
testcase_07 AC 25 ms
6,940 KB
testcase_08 AC 28 ms
6,940 KB
testcase_09 AC 6 ms
6,944 KB
testcase_10 AC 22 ms
6,940 KB
testcase_11 AC 74 ms
6,940 KB
testcase_12 AC 91 ms
6,940 KB
testcase_13 AC 16 ms
6,940 KB
testcase_14 AC 59 ms
6,944 KB
testcase_15 AC 7 ms
6,944 KB
testcase_16 AC 64 ms
6,940 KB
testcase_17 AC 25 ms
6,940 KB
testcase_18 AC 129 ms
6,940 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 10 ms
6,940 KB
testcase_21 AC 95 ms
6,940 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 154 ms
6,944 KB
testcase_24 AC 147 ms
6,940 KB
testcase_25 AC 154 ms
6,944 KB
testcase_26 AC 180 ms
6,944 KB
testcase_27 AC 148 ms
6,940 KB
testcase_28 AC 154 ms
6,944 KB
testcase_29 AC 151 ms
6,940 KB
testcase_30 AC 180 ms
6,940 KB
testcase_31 AC 149 ms
6,940 KB
testcase_32 AC 153 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0