結果

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int INF = 2e9;
const ll LINF = 2e18;

#define rep(i, n) for (int i = 0; (i) < (n); (i)++)
#define rep1(i, n) for (int i = 1; (i) < ((n) + 1); (i)++)
#define all(a) (a).begin(), (a).end()

const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};

int main(){
  ll N,K,Q;
  cin>>N>>K>>Q;
  vector<ll> A(N);
  priority_queue<ll, vector<ll>, less<ll>> P1;
  priority_queue<ll, vector<ll>, greater<ll>> P2;
  rep(i,N){
    cin>>A[i];
  }

  sort(all(A));
  rep(i,N){
    if(i < K){
      P1.push(A[i]);
    } else {
      P2.push(A[i]);
    }
  }

  while(Q--){
    int q;
    cin>>q;
    if(q==1){
      ll x;
      cin>>x;
      if(P1.top() > x){
        auto t = P1.top();
        P1.pop();
        P1.push(x);
        P2.push(t);
      } else {
        P2.push(x);
      }
    } else if(q==2){
      ll y;
      cin>>y;
      auto t = P1.top();
      if(P2.empty() || t+y <= P2.top()){
        P1.pop();
        P1.push(t+y);
      } else {
        auto u = P2.top();
        P1.pop();
        P2.pop();
        P1.push(u);
        P2.push(t+y);
      }
    } else {
      cout<<P1.top()<<endl;
    }
  }
}
0