結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 298 ms
5,376 KB
testcase_04 AC 188 ms
5,792 KB
testcase_05 AC 173 ms
5,856 KB
testcase_06 AC 178 ms
5,580 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 97 ms
5,376 KB
testcase_13 AC 96 ms
5,376 KB
testcase_14 AC 94 ms
5,376 KB
testcase_15 AC 98 ms
5,376 KB
testcase_16 AC 97 ms
5,376 KB
testcase_17 AC 109 ms
5,376 KB
testcase_18 AC 121 ms
5,376 KB
testcase_19 AC 130 ms
5,376 KB
testcase_20 AC 140 ms
5,376 KB
testcase_21 AC 153 ms
5,376 KB
testcase_22 AC 161 ms
5,452 KB
testcase_23 AC 169 ms
5,376 KB
testcase_24 AC 181 ms
5,376 KB
testcase_25 AC 191 ms
5,376 KB
testcase_26 AC 200 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 62 ms
5,376 KB
testcase_31 AC 64 ms
5,376 KB
testcase_32 AC 1 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 #

#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.pop();
            }
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}
0