結果

問題 No.649 ここでちょっとQK!
ユーザー 0w10w1
提出日時 2020-03-13 15:19:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 3,000 ms
コード長 867 bytes
コンパイル時間 2,688 ms
コンパイル使用メモリ 204,428 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-05-01 21:53:08
合計ジャッジ時間 7,008 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 268 ms
5,376 KB
testcase_04 AC 230 ms
12,800 KB
testcase_05 AC 226 ms
12,800 KB
testcase_06 AC 224 ms
12,928 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 116 ms
7,296 KB
testcase_13 AC 114 ms
7,296 KB
testcase_14 AC 110 ms
7,168 KB
testcase_15 AC 117 ms
7,296 KB
testcase_16 AC 112 ms
7,552 KB
testcase_17 AC 129 ms
7,808 KB
testcase_18 AC 141 ms
8,192 KB
testcase_19 AC 158 ms
8,576 KB
testcase_20 AC 173 ms
8,960 KB
testcase_21 AC 192 ms
9,344 KB
testcase_22 AC 202 ms
9,600 KB
testcase_23 AC 211 ms
10,112 KB
testcase_24 AC 237 ms
10,368 KB
testcase_25 AC 240 ms
10,752 KB
testcase_26 AC 253 ms
11,264 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 82 ms
7,168 KB
testcase_31 AC 83 ms
7,552 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 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;
  auto balance = [&]() {
    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());
    }
  };
  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());
      }
      balance();
    } else {
      if (bag0.size() == K) {
        cout << *--bag0.end() << endl;
        bag0.erase(--bag0.end());
      } else {
        cout << -1 << endl;
      }
      balance();
    }
  }

  return 0;
}
0