結果

問題 No.649 ここでちょっとQK!
ユーザー peroonperoon
提出日時 2019-04-27 12:51:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 3,000 ms
コード長 1,181 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 171,348 KB
実行使用メモリ 5,596 KB
最終ジャッジ日時 2023-08-18 12:20:14
合計ジャッジ時間 7,600 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 274 ms
4,376 KB
testcase_04 AC 67 ms
5,596 KB
testcase_05 AC 62 ms
5,548 KB
testcase_06 AC 58 ms
5,332 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 46 ms
4,380 KB
testcase_13 AC 45 ms
4,380 KB
testcase_14 AC 45 ms
4,376 KB
testcase_15 AC 48 ms
4,384 KB
testcase_16 AC 42 ms
4,376 KB
testcase_17 AC 51 ms
4,416 KB
testcase_18 AC 56 ms
4,420 KB
testcase_19 AC 62 ms
4,380 KB
testcase_20 AC 67 ms
4,628 KB
testcase_21 AC 72 ms
4,496 KB
testcase_22 AC 76 ms
4,552 KB
testcase_23 AC 82 ms
4,732 KB
testcase_24 AC 86 ms
4,532 KB
testcase_25 AC 92 ms
4,808 KB
testcase_26 AC 96 ms
4,500 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 38 ms
4,376 KB
testcase_31 AC 38 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

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

    // input
    ll Q, K;
    cin >> Q >> K;

    priority_queue<ll> que; // 大きい順
    priority_queue<ll, vector<ll>, greater<ll> > que2; // 小さい順

    FOR(i, 0, Q){
        ll id;
        cin >> id;

        if(id==1){
            ll v;
            cin >> v;
            que.push(v);
            if(que.size()>K){
                ll a = que.top();
                que.pop();
                que2.push(a);
            }
        }
        else{
            if(que.size()<K){
                p(-1);
            }else{
                ll a = que.top();
                que.pop();
                p(a);

                if(que2.size()>0){
                    ll b = que2.top();
                    que2.pop();
                    que.push(b);
                }
            }
        }
    }
    
    return 0;
}
0