結果

問題 No.649 ここでちょっとQK!
ユーザー 0w10w1
提出日時 2020-03-13 15:20:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 3,000 ms
コード長 803 bytes
コンパイル時間 1,865 ms
コンパイル使用メモリ 202,220 KB
実行使用メモリ 12,744 KB
最終ジャッジ日時 2023-08-14 09:19:12
合計ジャッジ時間 7,332 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 251 ms
4,380 KB
testcase_04 AC 212 ms
12,744 KB
testcase_05 AC 207 ms
12,688 KB
testcase_06 AC 214 ms
12,660 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 109 ms
7,172 KB
testcase_13 AC 110 ms
7,136 KB
testcase_14 AC 109 ms
7,076 KB
testcase_15 AC 112 ms
7,116 KB
testcase_16 AC 109 ms
7,460 KB
testcase_17 AC 121 ms
7,840 KB
testcase_18 AC 134 ms
8,156 KB
testcase_19 AC 158 ms
8,448 KB
testcase_20 AC 173 ms
8,928 KB
testcase_21 AC 178 ms
9,372 KB
testcase_22 AC 200 ms
9,840 KB
testcase_23 AC 227 ms
10,064 KB
testcase_24 AC 233 ms
10,468 KB
testcase_25 AC 251 ms
10,736 KB
testcase_26 AC 255 ms
11,188 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 80 ms
7,244 KB
testcase_31 AC 83 ms
7,444 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int Q, K;
  cin >> Q >> K;

  multiset<int64_t> bag0;
  multiset<int64_t> bag1;
  while (Q--) {
    int P;
    cin >> P;
    if (P == 1) {
      int64_t V;
      cin >> V;
      bag0.insert(V);
      if (bag1.size() && *bag1.begin() < *--bag0.end()) {
        bag1.insert(*--bag0.end());
        bag0.erase(--bag0.end());
      }
    } else {
      if (bag0.size() == K) {
        cout << *--bag0.end() << endl;
        bag0.erase(--bag0.end());
      } else {
        cout << -1 << endl;
      }
    }
    while (bag0.size() < K && bag1.size()) {
      bag0.insert(*bag1.begin());
      bag1.erase(bag1.begin());
    }
    while (bag0.size() > K) {
      bag1.insert(*--bag0.end());
      bag0.erase(--bag0.end());
    }
  }

  return 0;
}
0