結果

問題 No.649 ここでちょっとQK!
ユーザー kekenxkekenx
提出日時 2020-02-09 10:17:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 731 bytes
コンパイル時間 1,804 ms
コンパイル使用メモリ 173,348 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 12:01:46
合計ジャッジ時間 4,862 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_05 AC 60 ms
6,676 KB
testcase_06 AC 59 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 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 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 41 ms
6,676 KB
testcase_31 AC 37 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) {
      int 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