結果

問題 No.649 ここでちょっとQK!
コンテスト
ユーザー kyuna
提出日時 2019-08-24 14:02:33
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 154 ms / 3,000 ms
コード長 945 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 656 ms
コンパイル使用メモリ 93,032 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-01 22:42:01
合計ジャッジ時間 4,588 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
template<class T> using max_heap = priority_queue<T>;
template<class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;

int main() {
    max_heap<long long> small;
    min_heap<long long> large;
    int q, k; cin >> q >> k;
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            long long v; cin >> v;
            if (small.size() < k) {
                small.emplace(v);
                continue;
            }
            small.emplace(v);
            large.emplace(small.top()); small.pop();
        } else {
            if (small.size() < k) {
                cout << -1 << endl;
                continue;
            }
            cout << small.top() << endl; small.pop();
            if (!large.empty()) {
                small.emplace(large.top()); large.pop();
            }
        }
    }
    return 0;
}
0