結果

問題 No.649 ここでちょっとQK!
ユーザー ふーらくたる
提出日時 2018-03-22 00:12:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 3,000 ms
コード長 981 bytes
コンパイル時間 1,015 ms
コンパイル使用メモリ 77,840 KB
実行使用メモリ 5,936 KB
最終ジャッジ日時 2024-06-24 19:44:46
合計ジャッジ時間 4,815 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <functional>
using namespace std;

using int64 = long long;

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

    int Q, K;
    cin >> Q >> K;

    priority_queue<int64> S;                                    // 値が大きい方から出てくる
    priority_queue<int64, vector<int64>, greater<int64>> T;     // 値が小さい方から出てくる

    for (int i = 0; i < Q; i++) {
        int type;
        cin >> type;

        if (type == 1) {
            int64 v;
            cin >> v;

            S.push(v);

            if (S.size() > K) {
                T.push(S.top());
                S.pop();
            }
        } else if (S.size() < K) {
            cout << -1 << '\n';
        } else {
            cout << S.top() << '\n';
            S.pop();

            if (T.size() > 0) {
                S.push(T.top());
                T.pop();
            }
        }
    }

    return 0;
}
0