結果

問題 No.2804 Fixer And Ratism
ユーザー t98slider
提出日時 2024-07-13 20:45:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,251 bytes
コンパイル時間 2,825 ms
コンパイル使用メモリ 215,516 KB
最終ジャッジ日時 2025-02-22 06:33:58
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, Q;
    cin >> n >> Q;
    vector<pair<int, string>> a, b;
    while(Q--){
        int cmd;
        cin >> cmd;
        if(cmd == 1){
            int r;
            string s;
            cin >> s >> r;
            b.emplace_back(r, s);
            sort(b.rbegin(), b.rend());
        }else if(cmd == 2){
            int x;
            cin >> x;
            n -= x;
        }else{
            string s;
            int x;
            cin >> s >> x;
            n += x;
            for(int i = 0; i < b.size(); i++){
                if(b[i].second == s){
                    a.emplace_back(b[i]);
                    b.erase(b.begin() + i);
                    break;
                }
            }
            sort(a.rbegin(), a.rend());
        }
        vector<pair<int, string>> c;
        while(a.size() + b.size() > n){
            if(!b.empty()){
                c.emplace_back(b.back());
                b.pop_back();
            }else{
                c.emplace_back(a.back());
                a.pop_back();
            }
        }
        sort(c.begin(), c.end());
        for(auto &&[r, ss] : c) cout << ss << '\n';
    }
}
0