結果

問題 No.3298 K-th Slime
ユーザー askr58
提出日時 2025-10-05 14:35:48
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 3,259 ms
コンパイル使用メモリ 286,836 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-05 14:36:09
合計ジャッジ時間 5,746 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
	int n,k,q;
	cin>>n>>k>>q;
	vector<ll> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	priority_queue<ll> pq1;
	priority_queue<ll,vector<ll>,greater<ll>> pq2;
	for(int i=0;i<k;i++)pq1.push(a[i]);
	for(int i=k;i<n;i++)pq2.push(a[i]);
	while(q--){
		int t;
		cin>>t;
		if(t==1){
			ll x;
			cin>>x;
			if(pq1.top()<=x){
				pq2.push(x);
			}else{
				pq1.push(x);
				pq2.push(pq1.top());
				pq1.pop();
			}
		}else if(t==2){
			ll y;
			cin>>y;
			ll x=pq1.top()+y;
			pq1.pop();
			if(pq2.empty()){
				pq1.push(x);
				continue;
			}
			if(pq2.top()>=x)pq1.push(x);
			else {
				pq1.push(pq2.top());
				pq2.push(x);
				pq2.pop();
			}
		}else{
			cout<<pq1.top()<<endl;
		}
	}
}
0