結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 299 ms
5,376 KB
testcase_04 AC 264 ms
12,672 KB
testcase_05 AC 253 ms
12,800 KB
testcase_06 AC 253 ms
12,800 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 136 ms
7,168 KB
testcase_13 AC 137 ms
7,168 KB
testcase_14 AC 135 ms
7,040 KB
testcase_15 AC 140 ms
7,424 KB
testcase_16 AC 139 ms
7,680 KB
testcase_17 AC 160 ms
7,936 KB
testcase_18 AC 173 ms
8,320 KB
testcase_19 AC 193 ms
8,576 KB
testcase_20 AC 209 ms
8,960 KB
testcase_21 AC 225 ms
9,344 KB
testcase_22 AC 250 ms
9,728 KB
testcase_23 AC 263 ms
10,112 KB
testcase_24 AC 283 ms
10,496 KB
testcase_25 AC 308 ms
10,880 KB
testcase_26 AC 324 ms
11,264 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 99 ms
7,168 KB
testcase_31 AC 99 ms
7,680 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 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;
  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