結果

問題 No.649 ここでちょっとQK!
ユーザー face4face4
提出日時 2018-11-18 19:37:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 3,000 ms
コード長 791 bytes
コンパイル時間 565 ms
コンパイル使用メモリ 68,836 KB
実行使用メモリ 12,972 KB
最終ジャッジ日時 2023-08-26 01:59:04
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 21 ms
4,380 KB
testcase_04 AC 115 ms
12,972 KB
testcase_05 AC 109 ms
12,948 KB
testcase_06 AC 110 ms
12,892 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 56 ms
7,188 KB
testcase_13 AC 56 ms
7,208 KB
testcase_14 AC 55 ms
7,288 KB
testcase_15 AC 58 ms
7,476 KB
testcase_16 AC 56 ms
7,684 KB
testcase_17 AC 63 ms
7,996 KB
testcase_18 AC 72 ms
8,456 KB
testcase_19 AC 79 ms
8,700 KB
testcase_20 AC 84 ms
8,972 KB
testcase_21 AC 92 ms
9,372 KB
testcase_22 AC 100 ms
9,876 KB
testcase_23 AC 112 ms
10,212 KB
testcase_24 AC 117 ms
10,704 KB
testcase_25 AC 127 ms
10,996 KB
testcase_26 AC 134 ms
11,292 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 46 ms
7,320 KB
testcase_31 AC 48 ms
7,572 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
using namespace std;
typedef long long ll;

int main(){
    int q, k;
    scanf("%d %d", &q, &k);

    multiset<ll> s;
    multiset<ll>::iterator it = s.begin();

    int op;
    ll val;
    int siz = 0;

    for(int i = 0; i < q; i++){
        scanf("%d", &op);
        if(op == 1){
            scanf("%lld", &val);
            s.insert(val);
            siz++;
            if(siz == k){
                it = s.end();
                it--;
            }else if((*it) > val){
                it--;
            }
        }else if(op == 2){
            if(siz >= k){
                printf("%lld\n", *it);
                it = s.erase(it);
                siz--;
            }else{
                printf("-1\n");
            }
        }
    }

    return 0;
}
0