結果

問題 No.649 ここでちょっとQK!
ユーザー 0w1
提出日時 2018-04-15 03:05:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 301 ms / 3,000 ms
コード長 776 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 199,244 KB
最終ジャッジ日時 2025-01-05 10:14:55
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

signed main() {
  ios::sync_with_stdio(false);
  int Q, K;
  cin >> Q >> K;
  priority_queue<int64_t> lpq, gpq;
  for (int qi = 0; qi < Q; ++qi) {
    int OP;
    cin >> OP;
    if (OP == 1) {
      int64_t V;
      cin >> V;
      if (lpq.size() < K) {
        lpq.emplace(V);
      } else {
        if (V >= lpq.top()) {
          gpq.emplace(-V);
        } else {
          lpq.emplace(V);
          gpq.emplace(-lpq.top());
          lpq.pop();
        }
      }
    } else {
      if (lpq.size() < K) {
        cout << -1 << endl;
      } else {
        cout << lpq.top() << endl;
        lpq.pop();
        if (gpq.size()) {
          lpq.emplace(-gpq.top());
          gpq.pop();
        }
      }
    }
  }
  return 0;
}
0