結果

問題 No.3298 K-th Slime
ユーザー Rumain831
提出日時 2025-10-05 16:42:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 83,352 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2025-10-05 16:42:45
合計ジャッジ時間 3,763 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
using ll = long long;

int main(void){
  int n, k, q; cin >> n >> k >> q;
  multiset<ll> small, big;
  big.insert(1e18);
  for(int i=0; i<n; i++){
    ll a; cin >> a; small.insert(a);
  }
  auto f=[&](){
    while(small.size()>k){
      auto p=prev(small.end());
      big.insert(*p);
      small.erase(p);
    }
    while(small.size()<k){
      auto p=big.begin();
      small.insert(*p);
      big.erase(p);
    }
  };
  f();
  while(q--){
    int t; cin >> t;
    if(t==1){
      ll x; cin >> x;
      small.insert(x);
      f();
    }
    else if(t==2){
      ll y; cin >> y;
      auto p=prev(small.end());
      auto q=big.begin();
      ll ad=(*p)+y;
      small.erase(p);
      small.insert(ad);
      small.insert(*q);
      big.erase(q);
      f();
    }
    else{
      cout << *small.rbegin() << '\n';
    }
  }
  return 0;
}
0