結果

問題 No.649 ここでちょっとQK!
ユーザー 0w10w1
提出日時 2020-03-13 15:18:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 819 bytes
コンパイル時間 2,615 ms
コンパイル使用メモリ 201,720 KB
実行使用メモリ 12,896 KB
最終ジャッジ日時 2023-08-14 09:17:32
合計ジャッジ時間 11,133 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 295 ms
4,384 KB
testcase_04 AC 242 ms
12,752 KB
testcase_05 AC 238 ms
12,896 KB
testcase_06 AC 234 ms
12,752 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
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 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 2 ms
4,380 KB
testcase_33 WA -
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,388 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());
      }
      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());
      }
    } else {
      if (bag0.size() == K) {
        cout << *--bag0.end() << endl;
        bag0.erase(--bag0.end());
      } else {
        cout << -1 << endl;
      }
    }
  }

  return 0;
}
0