結果

問題 No.2804 Fixer And Ratism
ユーザー otoshigootoshigo
提出日時 2024-07-12 21:46:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 2,766 ms
コンパイル使用メモリ 231,176 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-12 21:47:04
合計ジャッジ時間 4,819 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 11 ms
5,376 KB
testcase_04 AC 8 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 20 ms
5,376 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 17 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 16 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 7 ms
5,376 KB
testcase_18 AC 24 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 23 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 28 ms
5,376 KB
testcase_24 AC 26 ms
5,376 KB
testcase_25 AC 29 ms
5,376 KB
testcase_26 AC 28 ms
5,376 KB
testcase_27 AC 27 ms
5,376 KB
testcase_28 AC 28 ms
5,376 KB
testcase_29 AC 28 ms
5,376 KB
testcase_30 AC 28 ms
5,376 KB
testcase_31 AC 26 ms
5,376 KB
testcase_32 AC 29 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,Q;
    cin>>N>>Q;
    set<pair<int,string>>A,B;
    map<string,int>mp;
    vector<string>ans;
    while(Q--){
        int t;
        cin>>t;
        if(t==1){
            string s;
            int r;
            cin>>s>>r;
            mp[s]=r;
            A.insert(make_pair(r,s));
        }else if(t==2){
            int x;
            cin>>x;
            N-=x;
        }else{
            string s;
            int x;
            cin>>s>>x;
            N+=x;
            if(A.count(make_pair(mp[s],s))){
                A.erase(make_pair(mp[s],s));
                B.insert(make_pair(mp[s],s));
            }
        }
        vector<pair<int,string>>vp;
        while((int)A.size()+(int)B.size()>N){
            if(A.size()){
                auto id=A.begin();
                vp.push_back(*id);
                A.erase(id);
            }else{
                auto id=B.begin();
                vp.push_back(*id);
                B.erase(id);
            }
        }
        sort(all(vp));
        for(auto[i,s]:vp)ans.push_back(s);
    }
    for(auto s:ans)cout<<s<<"\n";
}
0