結果

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

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
fast_io();
int n, q;
cin >> n >> q;
map<string, int> rate;
set<pair<int, string>> st_fixed, st_not_fixed;
for (; q--;) {
int type;
cin >> type;
if (type == 1) {
string s;
int r;
cin >> s >> r;
rate[s] = r;
st_not_fixed.insert({r, s});
if (st_fixed.size() + st_not_fixed.size() > n) {
auto it = st_not_fixed.begin();
cout << it->second << "\n";
st_not_fixed.erase(it);
}
} else if (type == 2) {
int x;
cin >> x;
n -= x;
vector<string> removed;
while (st_fixed.size() + st_not_fixed.size() > n) {
if (!st_not_fixed.empty()) {
auto it = st_not_fixed.begin();
removed.push_back(it->second);
st_not_fixed.erase(it);
} else {
auto it = st_fixed.begin();
removed.push_back(it->second);
st_fixed.erase(it);
}
}
sort(removed.begin(), removed.end(),
[&](string s1, string s2) { return rate[s1] < rate[s2]; });
for (string s : removed) {
cout << s << "\n";
}
} else {
string s;
int x;
cin >> s >> x;
n += x;
if (st_not_fixed.count({rate[s], s})) {
st_fixed.insert({rate[s], s});
st_not_fixed.erase({rate[s], s});
}
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0