結果

問題 No.649 ここでちょっとQK!
ユーザー packer_jppacker_jp
提出日時 2018-02-09 23:10:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,191 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 164,224 KB
実行使用メモリ 5,856 KB
最終ジャッジ日時 2024-04-17 07:47:50
合計ジャッジ時間 5,925 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 278 ms
5,376 KB
testcase_04 AC 181 ms
5,788 KB
testcase_05 AC 168 ms
5,856 KB
testcase_06 AC 170 ms
5,452 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int Q, K;
priority_queue<int> pq1;
priority_queue<int, vector<int>, greater<int> > pq2;
vector<int> ans;

signed main() {
    cin >> Q >> K;
    for (int i = 0; i < Q; i++) {
        int kind;
        cin >> kind;
        if (kind == 1) {
            int v;
            cin >> v;
            if (pq1.size() < K) {
                pq1.push(v);
            } else if (v < pq1.top()) {
                pq2.push(pq1.top());
                pq1.pop();
                pq1.push(v);
            } else {
                pq2.push(v);
            }
        } else {
            if (pq1.size() < K) {
                ans.push_back(-1);
            } else if (pq2.empty()) {
                ans.push_back(pq1.top());
                pq1.pop();
            } else {
                ans.push_back(pq1.top());
                pq1.pop();
                pq1.push(pq2.top());
                pq2.top();
            }
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}
0