結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int main() {
  lint n, k, q;
  cin >> n >> k >> q;
  vector<lint> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  multiset<lint> l, r;
  for (int i = 0; i < k; i++) l.insert(a[i]);
  for (int i = k; i < n; i++) r.insert(a[i]);
  for (int qu = 0; qu < q; qu++) {
    int t;
    cin >> t;
    if (t == 1) {
      lint x;
      cin >> x;
      l.insert(x);
      r.insert(*l.rbegin());
      l.erase(l.find(*l.rbegin()));
    }
    else if (t == 2) {
      lint y;
      cin >> y;
      lint high = *l.rbegin();
      l.erase(l.find(high));
      if (r.empty() || *r.begin() > high+y) l.insert(high+y);
      else {
        r.insert(high+y);
        l.insert(*r.begin());
        r.erase(r.find(*r.begin()));
      }
    }
    else if (t == 3) {
      cout << *l.rbegin() << endl;
    }
  }
}
0