結果

問題 No.2804 Fixer And Ratism
ユーザー highlighterhighlighter
提出日時 2024-07-04 16:56:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 3,420 ms
コンパイル使用メモリ 267,756 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-11 23:11:11
合計ジャッジ時間 7,194 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 39 ms
6,940 KB
testcase_04 AC 24 ms
6,944 KB
testcase_05 AC 11 ms
6,940 KB
testcase_06 AC 73 ms
6,944 KB
testcase_07 AC 24 ms
6,940 KB
testcase_08 AC 25 ms
6,944 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 20 ms
6,944 KB
testcase_11 AC 65 ms
6,944 KB
testcase_12 AC 55 ms
6,940 KB
testcase_13 AC 14 ms
6,940 KB
testcase_14 AC 54 ms
6,940 KB
testcase_15 AC 6 ms
6,940 KB
testcase_16 AC 58 ms
6,944 KB
testcase_17 AC 22 ms
6,940 KB
testcase_18 AC 98 ms
6,944 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 9 ms
6,940 KB
testcase_21 AC 83 ms
6,944 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 142 ms
6,944 KB
testcase_24 AC 140 ms
6,940 KB
testcase_25 AC 142 ms
6,940 KB
testcase_26 AC 140 ms
6,944 KB
testcase_27 AC 143 ms
6,944 KB
testcase_28 AC 141 ms
6,940 KB
testcase_29 AC 139 ms
6,944 KB
testcase_30 AC 140 ms
6,944 KB
testcase_31 AC 141 ms
6,944 KB
testcase_32 AC 141 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
	set<pair<int,string>> data1;
	set<pair<int,string>> data2;
	int N,Q;
	cin >> N >> Q;
	int P=0;
	for(;Q--;){
		int c;
		cin >> c;
		if(c==1){
			string s;
			int r;
			cin >> s >> r;
			if(N==0 && !data2.empty()){
				pair<int,string> p=*begin(data2);
				if(p.first<r){
					data2.erase(p);
					data2.insert(make_pair(r,s));
					cout << p.second << endl;
					continue;
				}
				cout << s << endl;
				continue;
			}
			if(N==0){
				cout << s << endl;
				continue;
			}
			P++;
			N--;
			data2.insert(make_pair(r,s));
			continue;
		}
		if(c==2){
			int x;
			cin >> x;
			priority_queue<pair<int,string>,vector<pair<int,string>>,greater<pair<int,string>>> data3;
			N-=x;
			while(N<0){
				P--;
				N++;
				if(!data2.empty()){
					pair<int,string> p=*begin(data2);
					data2.erase(p);
					data3.push(p);
					continue;
				}
				pair<int,string> p=*begin(data1);
				data1.erase(p);
				data3.push(p);
			}
			while(!data3.empty()){
				cout << data3.top().second << endl;
				data3.pop();
			}
			continue;
		}
		string s;
		int x;
		cin >> s >> x;
		N+=x;
		pair<int,string> q=make_pair(-1,s);
		for(auto p : data2){
			if(p.second==s){
				q.first=p.first;
				break;
			}
		}
		if(q.first!=-1){
			data2.erase(q);
			data1.insert(q);
		}
	}
}
0