結果

問題 No.649 ここでちょっとQK!
ユーザー hanyu
提出日時 2020-04-03 18:26:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 111 ms / 3,000 ms
コード長 651 bytes
コンパイル時間 1,402 ms
コンパイル使用メモリ 169,540 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-07-03 01:01:55
合計ジャッジ時間 4,873 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int q, k;
  cin >> q >> k;
  
  multiset<ll> ms;
  auto it = ms.begin();
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      ll v;
      cin >> v;
      ms.insert(v);
      if (ms.size() == k && it != ms.begin()) {
        it = ms.end();
        it--;
      }
      else if (ms.size() > k && *it > v) {
        it--;
      }
    }
    else {
      if (ms.size() < k) {
        cout << "-1\n";
      }
      else {
        cout << *it << '\n';
        it = ms.erase(it);
      }
    }
  }
}
0