結果

問題 No.3298 K-th Slime
コンテスト
ユーザー forest3
提出日時 2025-10-29 16:18:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 1,657 ms
コンパイル使用メモリ 166,072 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2025-10-29 16:19:00
合計ジャッジ時間 5,095 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, a, b) for (int i = a; i < b; i++)
using ll = long long;

int main(){
	int n, k, q;
	cin >> n >> k >> q;
	multiset<ll> sl, sh;
	rep(i, 0, n) {
		int a;
		cin >> a;
		int sz = sl.size();
		if(sz < k) sl.insert(a);
		else {
			ll e = *prev(sl.end());
			if(a < e) {
				sl.insert(a);
				sh.insert(e);
				sl.erase(prev(sl.end()));
			}
			else sh.insert(a);
		}
	}
	rep(qi, 0, q) {
		int t, x, y;
		cin >> t;
		if(t == 1) {
			cin >> x;
			ll e = *prev(sl.end());
			if(x < e) {
				sl.insert(x);
				sh.insert(e);
				sl.erase(prev(sl.end()));
			}
			else sh.insert(x);
		}
		else if(t == 2) {
			cin >> y;
			ll e = *prev(sl.end());
			sh.insert(e + y);
			sl.erase(prev(sl.end()));
			sl.insert(*sh.begin());
			sh.erase(sh.begin());
		}
		else cout << *prev(sl.end()) << endl;
	}
}
0