結果

問題 No.649 ここでちょっとQK!
ユーザー squidsquid
提出日時 2018-02-10 00:16:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 287 ms / 3,000 ms
コード長 1,021 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 164,216 KB
実行使用メモリ 5,856 KB
最終ジャッジ日時 2024-04-17 14:32:55
合計ジャッジ時間 6,387 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 287 ms
5,376 KB
testcase_04 AC 177 ms
5,816 KB
testcase_05 AC 168 ms
5,856 KB
testcase_06 AC 173 ms
5,456 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 95 ms
5,376 KB
testcase_13 AC 94 ms
5,376 KB
testcase_14 AC 91 ms
5,376 KB
testcase_15 AC 96 ms
5,376 KB
testcase_16 AC 89 ms
5,376 KB
testcase_17 AC 103 ms
5,376 KB
testcase_18 AC 111 ms
5,376 KB
testcase_19 AC 127 ms
5,376 KB
testcase_20 AC 142 ms
5,376 KB
testcase_21 AC 151 ms
5,376 KB
testcase_22 AC 152 ms
5,376 KB
testcase_23 AC 164 ms
5,376 KB
testcase_24 AC 175 ms
5,376 KB
testcase_25 AC 187 ms
5,376 KB
testcase_26 AC 206 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 61 ms
5,376 KB
testcase_31 AC 64 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//constant
const long long int inf = 1<<30;
const int N = 1e5+1;
const int M = 1e5+1;

//variable
int q,k;
priority_queue<long long int>s;
priority_queue<long long int, vector<long long int>, greater<long long int> > l;

//function


int main()
{
    cin>>q>>k;
    for(int i=0; i<q; i++){
        int que;
        cin>>que;
        if(que==1){
            long long int v;
            cin>>v;
            s.push(v);
            if(s.size()>k){
                long long int ob=s.top();
                l.push(ob);
                s.pop();
            }
        }
        if(que==2){
            if(s.size()<k){
                cout<<-1<<endl;
                continue;
            }

            cout<<s.top()<<endl;
            //cout<<'a'<<endl;
            s.pop();
            if(l.size()>0){
                long long int ob=l.top();
                //cout<<'b'<<endl;
                s.push(ob);
                l.pop();
            }
        }
    }

    return 0;
}
0