結果

問題 No.649 ここでちょっとQK!
ユーザー 0w10w1
提出日時 2020-03-13 15:19:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 3,000 ms
コード長 867 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 203,544 KB
実行使用メモリ 12,792 KB
最終ジャッジ日時 2023-08-14 09:18:28
合計ジャッジ時間 8,559 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 250 ms
4,376 KB
testcase_04 AC 210 ms
12,708 KB
testcase_05 AC 208 ms
12,792 KB
testcase_06 AC 206 ms
12,720 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 107 ms
7,120 KB
testcase_13 AC 113 ms
7,112 KB
testcase_14 AC 109 ms
7,104 KB
testcase_15 AC 110 ms
7,156 KB
testcase_16 AC 102 ms
7,524 KB
testcase_17 AC 125 ms
7,776 KB
testcase_18 AC 139 ms
8,260 KB
testcase_19 AC 144 ms
8,512 KB
testcase_20 AC 162 ms
8,916 KB
testcase_21 AC 183 ms
9,304 KB
testcase_22 AC 187 ms
9,836 KB
testcase_23 AC 210 ms
10,132 KB
testcase_24 AC 238 ms
10,464 KB
testcase_25 AC 249 ms
10,772 KB
testcase_26 AC 251 ms
11,132 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 76 ms
7,144 KB
testcase_31 AC 77 ms
7,444 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,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