結果

問題 No.3298 K-th Slime
ユーザー Hydrogen332
提出日時 2025-10-06 00:18:17
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 3,108 ms
コンパイル使用メモリ 284,188 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-06 00:18:22
合計ジャッジ時間 4,955 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	int N, K, Q;
	cin >> N >> K >> Q;
	
	priority_queue<ll> small;
	priority_queue<ll, vector<ll>, greater<ll>> large;
	
	rep(i, 0, N) {
		ll A;
		cin >> A;
		
		small.push(A);
		if (small.size() > K) {
			large.push(small.top());
			small.pop();
		}
	}
	
	rep(query, 0, Q) {
		int t;
		cin >> t;
		
		if (t == 1) {
			ll x;
			cin >> x;
			
			small.push(x);
			large.push(small.top());
			small.pop();
		} else if (t == 2) {
			ll y;
			cin >> y;
			y += small.top();
			
			if (large.empty()) {
				small.pop();
				small.push(y);
			} else {
				small.pop();
				small.push(large.top());
				large.pop();
				
				small.push(y);
				large.push(small.top());
				small.pop();
			}
		} else {
			cout << small.top() << '\n';
		}
	}
}
0