結果

問題 No.649 ここでちょっとQK!
ユーザー hanyuhanyu
提出日時 2020-04-03 18:26:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 3,000 ms
コード長 651 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 167,328 KB
実行使用メモリ 12,896 KB
最終ジャッジ日時 2023-09-15 23:49:15
合計ジャッジ時間 5,372 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 17 ms
4,380 KB
testcase_04 AC 112 ms
12,764 KB
testcase_05 AC 106 ms
12,700 KB
testcase_06 AC 109 ms
12,896 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 50 ms
7,092 KB
testcase_13 AC 51 ms
7,084 KB
testcase_14 AC 52 ms
7,076 KB
testcase_15 AC 52 ms
7,176 KB
testcase_16 AC 51 ms
7,556 KB
testcase_17 AC 58 ms
7,760 KB
testcase_18 AC 65 ms
8,240 KB
testcase_19 AC 70 ms
8,532 KB
testcase_20 AC 82 ms
8,892 KB
testcase_21 AC 87 ms
9,240 KB
testcase_22 AC 93 ms
9,736 KB
testcase_23 AC 94 ms
10,028 KB
testcase_24 AC 103 ms
10,388 KB
testcase_25 AC 111 ms
10,752 KB
testcase_26 AC 118 ms
11,100 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 44 ms
7,080 KB
testcase_31 AC 44 ms
7,524 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int q, k;
  cin >> q >> k;
  
  multiset<ll> ms;
  auto it = ms.begin();
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      ll v;
      cin >> v;
      ms.insert(v);
      if (ms.size() == k && it != ms.begin()) {
        it = ms.end();
        it--;
      }
      else if (ms.size() > k && *it > v) {
        it--;
      }
    }
    else {
      if (ms.size() < k) {
        cout << "-1\n";
      }
      else {
        cout << *it << '\n';
        it = ms.erase(it);
      }
    }
  }
}
0