結果

問題 No.649 ここでちょっとQK!
ユーザー Mister
提出日時 2020-08-18 11:22:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 187 ms / 3,000 ms
コード長 1,007 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 74,100 KB
最終ジャッジ日時 2025-01-13 02:57:53
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

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