結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
using ll = long long;
ll n, k, q, a[1 << 17];
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> k >> q;
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  priority_queue<ll> front;
  priority_queue<ll, vector<ll>, greater<>> back;
  rep(i, k - 1) front.push(a[i]);
  for (int i = k - 1; i < n; ++i) back.push(a[i]);
  rep(_, q) {
    int qt;
    cin >> qt;
    if (qt == 1) {
      ll x;
      cin >> x;
      if (back.top() <= x) {
        back.push(x);
      } else {
        front.push(x);
        back.push(front.top());
        front.pop();
      }
    } else if (qt == 2) {
      ll y;
      cin >> y;
      back.push(back.top() + y);
      back.pop();
    } else {
      cout << back.top() << '\n';
    }
  }
}
0