結果

問題 No.649 ここでちょっとQK!
ユーザー ふーらくたるふーらくたる
提出日時 2018-03-22 00:12:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 3,000 ms
コード長 981 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 77,836 KB
実行使用メモリ 5,636 KB
最終ジャッジ日時 2023-09-07 01:08:39
合計ジャッジ時間 6,376 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 23 ms
4,380 KB
testcase_04 AC 66 ms
5,636 KB
testcase_05 AC 62 ms
5,564 KB
testcase_06 AC 57 ms
5,336 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 32 ms
4,384 KB
testcase_13 AC 32 ms
4,380 KB
testcase_14 AC 31 ms
4,380 KB
testcase_15 AC 35 ms
4,380 KB
testcase_16 AC 29 ms
4,380 KB
testcase_17 AC 36 ms
4,380 KB
testcase_18 AC 40 ms
4,456 KB
testcase_19 AC 45 ms
4,392 KB
testcase_20 AC 47 ms
4,380 KB
testcase_21 AC 52 ms
4,648 KB
testcase_22 AC 55 ms
4,660 KB
testcase_23 AC 59 ms
4,512 KB
testcase_24 AC 60 ms
4,532 KB
testcase_25 AC 66 ms
4,620 KB
testcase_26 AC 70 ms
4,516 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 24 ms
4,380 KB
testcase_31 AC 24 ms
4,384 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,384 KB
testcase_35 AC 1 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

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