結果

問題 No.3298 K-th Slime
ユーザー hatsuka_iwa
提出日時 2025-10-09 03:03:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 765 bytes
コンパイル時間 2,618 ms
コンパイル使用メモリ 201,308 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-09 03:03:38
合計ジャッジ時間 6,682 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N, K, Q; cin >> N >> K >> Q;
  priority_queue<long long> APQ;
  priority_queue<long long, vector<long long>, greater<long long>> BPQ;
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    APQ.push(A);
    if ((int)APQ.size() >= K) {
      BPQ.push(APQ.top());
      APQ.pop();
    }
  }
  for (int i = 0; i < Q; i++) {
    int type; cin >> type;
    if (type == 1) {
      int x; cin >> x;
      if (x > APQ.top()) BPQ.push(x);
      else {
        APQ.push(x);
        BPQ.push(APQ.top());
        APQ.pop();
      }
    }
    if (type == 2) {
      int y; cin >> y;
      long long t = BPQ.top() + y;
      BPQ.pop();
      BPQ.push(t);
    }
    if (type == 3) cout << BPQ.top() << endl;
  }
}
0