結果

問題 No.649 ここでちょっとQK!
ユーザー MisterMister
提出日時 2020-08-18 11:22:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 3,000 ms
コード長 1,007 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 77,124 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-04-20 07:26:37
合計ジャッジ時間 4,252 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 24 ms
6,944 KB
testcase_04 AC 139 ms
12,928 KB
testcase_05 AC 147 ms
12,672 KB
testcase_06 AC 132 ms
12,800 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 53 ms
7,424 KB
testcase_13 AC 53 ms
7,168 KB
testcase_14 AC 53 ms
7,296 KB
testcase_15 AC 57 ms
7,296 KB
testcase_16 AC 50 ms
7,808 KB
testcase_17 AC 63 ms
7,808 KB
testcase_18 AC 70 ms
8,320 KB
testcase_19 AC 77 ms
8,576 KB
testcase_20 AC 86 ms
9,216 KB
testcase_21 AC 94 ms
9,472 KB
testcase_22 AC 105 ms
9,856 KB
testcase_23 AC 114 ms
10,240 KB
testcase_24 AC 129 ms
10,496 KB
testcase_25 AC 136 ms
10,880 KB
testcase_26 AC 146 ms
11,392 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 45 ms
7,424 KB
testcase_31 AC 49 ms
7,552 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>

using lint = long long;

void solve() {
    int q, k;
    std::cin >> q >> k;

    std::multiset<lint> big, small;
    auto insert = [&](lint x) {
        big.insert(x);
        if ((int)big.size() >= k) {
            lint y = *big.rbegin();
            big.erase(big.find(y));
            small.insert(y);
        }
    };

    while (q--) {
        int t;
        std::cin >> t;

        switch (t) {
            case 1: {
                lint x;
                std::cin >> x;
                insert(x);
                break;
            }

            case 2: {
                if (small.empty()) {
                    std::cout << -1 << "\n";
                } else {
                    auto x = *small.begin();
                    small.erase(small.find(x));
                    std::cout << x << "\n";
                }
            }
        }
    }
}

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

    solve();

    return 0;
}
0