結果

問題 No.649 ここでちょっとQK!
ユーザー ミドリムシミドリムシ
提出日時 2018-02-09 23:06:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 299 ms / 3,000 ms
コード長 1,216 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 77,208 KB
実行使用メモリ 5,908 KB
最終ジャッジ日時 2024-04-17 06:02:08
合計ジャッジ時間 6,037 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 299 ms
5,376 KB
testcase_04 AC 202 ms
5,908 KB
testcase_05 AC 197 ms
5,856 KB
testcase_06 AC 187 ms
5,712 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 110 ms
5,376 KB
testcase_13 AC 106 ms
5,376 KB
testcase_14 AC 106 ms
5,376 KB
testcase_15 AC 113 ms
5,376 KB
testcase_16 AC 100 ms
5,376 KB
testcase_17 AC 119 ms
5,376 KB
testcase_18 AC 128 ms
5,376 KB
testcase_19 AC 140 ms
5,376 KB
testcase_20 AC 151 ms
5,376 KB
testcase_21 AC 161 ms
5,376 KB
testcase_22 AC 174 ms
5,376 KB
testcase_23 AC 185 ms
5,376 KB
testcase_24 AC 197 ms
5,376 KB
testcase_25 AC 208 ms
5,376 KB
testcase_26 AC 219 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 71 ms
5,376 KB
testcase_31 AC 69 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int Q, K;
    cin >> Q >> K;
    priority_queue<long, vector<long>, less<long>> K_left;
    long Kth = -1;
    priority_queue<long, vector<long>, greater<long>> K_right;
    int array_size = 0;
    for(int i = 0; i < Q; i++){
        int type;
        cin >> type;
        if(type == 1){
            long num;
            cin >> num;
            array_size++;
            K_left.push(num);
            if(array_size == K){
                Kth = K_left.top();
                K_left.pop();
            }else if(array_size > K){
                K_right.push(Kth);
                K_right.push(K_left.top());
                K_left.pop();
                Kth = K_right.top();
                K_right.pop();
            }
        }else{
            if(array_size < K){
                cout << -1 << endl;
            }else{
                array_size--;
                cout << Kth << endl;
                if(array_size >= K){
                    Kth = K_right.top();
                    K_right.pop();
                }else{
                    Kth = -1;
                }
            }
        }
    }
}
0