結果

問題 No.649 ここでちょっとQK!
ユーザー stderrstderr
提出日時 2018-02-11 18:27:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 271 ms / 3,000 ms
コード長 1,061 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 70,008 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-04-28 16:41:07
合計ジャッジ時間 6,491 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 271 ms
6,944 KB
testcase_04 AC 144 ms
12,672 KB
testcase_05 AC 102 ms
12,544 KB
testcase_06 AC 103 ms
12,928 KB
testcase_07 AC 2 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 72 ms
7,168 KB
testcase_13 AC 72 ms
7,168 KB
testcase_14 AC 72 ms
7,040 KB
testcase_15 AC 83 ms
7,168 KB
testcase_16 AC 78 ms
7,552 KB
testcase_17 AC 92 ms
7,936 KB
testcase_18 AC 109 ms
8,192 KB
testcase_19 AC 122 ms
8,448 KB
testcase_20 AC 135 ms
8,960 KB
testcase_21 AC 141 ms
9,216 KB
testcase_22 AC 157 ms
9,728 KB
testcase_23 AC 171 ms
9,856 KB
testcase_24 AC 186 ms
10,240 KB
testcase_25 AC 195 ms
10,624 KB
testcase_26 AC 209 ms
11,136 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 65 ms
7,168 KB
testcase_31 AC 75 ms
7,424 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 <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.end()); S.erase(--S.end());
        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