結果

問題 No.649 ここでちょっとQK!
ユーザー kekenxkekenx
提出日時 2020-02-09 10:20:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 3,000 ms
コード長 730 bytes
コンパイル時間 1,937 ms
コンパイル使用メモリ 173,348 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 12:02:00
合計ジャッジ時間 5,134 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 25 ms
6,676 KB
testcase_04 AC 75 ms
6,676 KB
testcase_05 AC 61 ms
6,676 KB
testcase_06 AC 61 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 47 ms
6,676 KB
testcase_13 AC 46 ms
6,676 KB
testcase_14 AC 48 ms
6,676 KB
testcase_15 AC 48 ms
6,676 KB
testcase_16 AC 36 ms
6,676 KB
testcase_17 AC 48 ms
6,676 KB
testcase_18 AC 55 ms
6,676 KB
testcase_19 AC 61 ms
6,676 KB
testcase_20 AC 65 ms
6,676 KB
testcase_21 AC 70 ms
6,676 KB
testcase_22 AC 74 ms
6,676 KB
testcase_23 AC 79 ms
6,676 KB
testcase_24 AC 85 ms
6,676 KB
testcase_25 AC 91 ms
6,676 KB
testcase_26 AC 98 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 3 ms
6,676 KB
testcase_30 AC 40 ms
6,676 KB
testcase_31 AC 38 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int q, k;
priority_queue<ll, vector<ll>, greater<ll>> minq;
priority_queue<ll> maxq;

void f1() {
  ll v;
  scanf("%lld", &v);

  if (maxq.size() < k) {
    maxq.push(v);
  } else {
    if (maxq.top() > v) {
      ll tmp = maxq.top(); maxq.pop();
      maxq.push(v);
      v = tmp;
    }
    minq.push(v);
  }
}

void f2() {
  if (maxq.size() < k) {
    puts("-1");
  } else {
    cout << maxq.top() << endl;
    maxq.pop();
    if (minq.size() > 0) {
      maxq.push(minq.top()); minq.pop();
    }
  }
}

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

  while (q--) {
    int query;
    scanf("%d", &query);
    if (query == 1) f1();
    else f2();
  }
  return 0;
}
0