結果

問題 No.649 ここでちょっとQK!
ユーザー T1610T1610
提出日時 2018-02-13 01:56:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 269 ms / 3,000 ms
コード長 1,393 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 172,616 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-05 11:40:41
合計ジャッジ時間 6,443 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 269 ms
6,944 KB
testcase_04 AC 166 ms
6,940 KB
testcase_05 AC 156 ms
6,944 KB
testcase_06 AC 160 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 90 ms
6,944 KB
testcase_13 AC 85 ms
6,940 KB
testcase_14 AC 84 ms
6,944 KB
testcase_15 AC 89 ms
6,940 KB
testcase_16 AC 90 ms
6,940 KB
testcase_17 AC 102 ms
6,940 KB
testcase_18 AC 106 ms
6,944 KB
testcase_19 AC 117 ms
6,940 KB
testcase_20 AC 127 ms
6,944 KB
testcase_21 AC 135 ms
6,944 KB
testcase_22 AC 144 ms
6,940 KB
testcase_23 AC 153 ms
6,944 KB
testcase_24 AC 165 ms
6,940 KB
testcase_25 AC 174 ms
6,940 KB
testcase_26 AC 183 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 54 ms
6,944 KB
testcase_31 AC 56 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int q, k;
    cin >> q >> k;
    priority_queue<ll> q1;
    priority_queue<ll,vector<ll>,greater<ll> > q2;
    rep(i, q) {
        ll a, b;
        cin >> a;
        if(a == 1) {
            cin >> b;
            if(q1.size() < k) q1.push(b);
            else {
                if(q1.top() > b) {
                    q2.push(q1.top());
                    q1.pop();
                    q1.push(b);
                }
                else q2.push(b);
            } 
        }
        if(a == 2) {
            if(q1.size() < k) {
                cout << -1 << endl;
            }
            else {
                cout << q1.top() << endl;
                q1.pop();
                if(q2.size() > 0) {
                    q1.push(q2.top());
                    q2.pop();
                }
            }
        }
    }

    return 0;
}
0