結果

問題 No.3298 K-th Slime
ユーザー yu23578
提出日時 2025-10-05 15:38:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 205,356 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-05 15:38:49
合計ジャッジ時間 4,048 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

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

signed main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  vector<int> A(N);
  for(int i = 0; i < N; i++) cin>>A[i];
  sort(A.begin(),A.end());
  priority_queue<int> small;
  priority_queue<int,vector<int>,greater<int>> large;
  for(int i = 0; i < K; i++){
  	small.push(A[i]);
  }
  for(int i = K; i < N; i++){
  	large.push(A[i]);
  }
  large.push(1e18);
  for(int i = 0; i < Q; i++){
  	int q; cin>>q;
  	if(q == 1){
  		int x; cin>>x;
  		if(small.top() < x){
  			large.push(x);
  		}
  		else{
  			small.push(x);
  			large.push(small.top());
  			small.pop();
  		}
  	}
  	if(q == 2){
  		int y; cin>>y;
  		int now = small.top();
  		small.pop();
  		small.push(large.top());
  		large.pop();
  		now += y;
  		if(small.top() < now){
  			large.push(now);
  		}
  		else{
  			small.push(now);
  			large.push(small.top());
  			small.pop();
  		}
  	}
  	if(q == 3){
  		cout << small.top() << "\n";
  	}
  }
}
0