結果

問題 No.649 ここでちょっとQK!
ユーザー stderrstderr
提出日時 2018-02-11 15:22:24
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,068 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 70,012 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-04-28 07:38:53
合計ジャッジ時間 7,661 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 275 ms
5,376 KB
testcase_04 RE -
testcase_05 AC 102 ms
12,800 KB
testcase_06 AC 103 ms
12,544 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  multiset<ll> S, T;
  ull Q, K;
  cin >> Q >> K;
  // cout << "Q:" << Q << " K:" << K << endl;
  rep(i, Q) {
    int q;
    cin >> q;
    if (q == 1) {
      ll v;
      cin >> v;
      if (S.size() < K - 1) S.insert(v);
      else if (S.empty()) T.insert(v);
      else if (v >= *S.rbegin()) T.insert(v);
      else {
        S.insert(v);
        ll tmp = *S.rbegin(); S.erase(S.rbegin().base());
        T.insert(tmp);
      }
    } else if (q == 2) {
      if (!T.empty()) {
        ll tmp = *T.begin(); T.erase(T.begin());
        cout << tmp << endl;
      } else {
        cout << -1 << endl;
      }
    }
  }
  return 0;
}
0