結果

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

ソースコード

diff #

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

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using mint = modint998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    priority_queue<ll> low;
    priority_queue<ll, vector<ll>, greater<ll>> high;
    for(int i = 0; i < N; i++) {
        if(i < K) low.push(A[i]);
        else high.push(A[i]);
    }

    while(Q--) {
        int t;
        cin >> t;
        if(t == 1) {
            ll x;
            cin >> x;

            low.push(x);
            high.push(low.top());
            low.pop();
        }else if(t == 2) {
            ll y;
            cin >> y;

            ll x = low.top();
            low.pop();
            low.push(x + y);
            if(!high.empty() && low.top() > high.top()) {
                ll p = low.top();
                ll q = high.top();
                low.pop();
                high.pop();
                low.push(q);
                high.push(p);
            }
        }else {
            cout << low.top() << "\n";
        }
    }
}
0