結果

問題 No.649 ここでちょっとQK!
ユーザー kyuna
提出日時 2019-08-24 14:25:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 274 ms / 3,000 ms
コード長 856 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 76,176 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-10-14 12:45:56
合計ジャッジ時間 6,159 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    multiset<long long> small;
    multiset<long long> large;
    int q, k; cin >> q >> k;
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            long long v; cin >> v;
            small.emplace(v);
            if (small.size() > k) {
                large.emplace(*small.rbegin());
                small.erase(--small.end());
            }
        } else {
            if (small.size() < k) {
                cout << -1 << endl;
                continue;
            }
            cout << *small.rbegin() << endl;
            small.erase(--small.end());
            if (!large.empty()) {
                small.emplace(*large.begin());
                large.erase(large.begin());
            }
        }
    }
    return 0;
}
0