結果

問題 No.649 ここでちょっとQK!
ユーザー recososorecososo
提出日時 2020-03-05 15:39:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 3,000 ms
コード長 996 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 169,640 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 02:34:32
合計ジャッジ時間 6,946 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 271 ms
6,940 KB
testcase_04 AC 173 ms
6,940 KB
testcase_05 AC 163 ms
6,940 KB
testcase_06 AC 162 ms
6,944 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 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 89 ms
6,944 KB
testcase_13 AC 88 ms
6,940 KB
testcase_14 AC 87 ms
6,940 KB
testcase_15 AC 92 ms
6,944 KB
testcase_16 AC 89 ms
6,944 KB
testcase_17 AC 99 ms
6,940 KB
testcase_18 AC 113 ms
6,944 KB
testcase_19 AC 120 ms
6,944 KB
testcase_20 AC 132 ms
6,944 KB
testcase_21 AC 137 ms
6,940 KB
testcase_22 AC 147 ms
6,940 KB
testcase_23 AC 157 ms
6,944 KB
testcase_24 AC 170 ms
6,940 KB
testcase_25 AC 185 ms
6,944 KB
testcase_26 AC 192 ms
6,940 KB
testcase_27 AC 3 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 57 ms
6,944 KB
testcase_31 AC 59 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    priority_queue<ll,vector<ll>,greater<ll>> pq2;
    priority_queue<ll> pq;
    int q,k;cin >> q >> k;
    while(q--){
        int x;cin >> x;
        if(x==1){
            ll v;cin >> v;
            if(pq.size()<k){
                pq.push(v);
            }
            else{
                if(v<pq.top()){
                    ll p=pq.top();
                    pq.pop();
                    pq.push(v);
                    pq2.push(p);
                }
                else{
                    pq2.push(v);
                }
            }
        }
        else{
            if(pq.size()<k){
                cout << -1 << endl;
            }
            else{
                cout << pq.top() << endl;
                pq.pop();
                if(!pq2.empty()){
                    ll p=pq2.top();
                    pq2.pop();
                    pq.push(p);
                }
            }
        }
    }
}
0