結果

問題 No.649 ここでちょっとQK!
ユーザー Konton7
提出日時 2020-01-24 08:45:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 325 ms / 3,000 ms
コード長 1,247 bytes
コンパイル時間 2,697 ms
コンパイル使用メモリ 198,004 KB
最終ジャッジ日時 2025-01-08 20:34:07
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
// #define DEBUG


int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int q, t, k, x;
    ll y;
    cin >> q >> k;
    priority_queue<ll> p, r;
    rep(i, q){
        cin >> x;
        if (x == 1){
            cin >> y;
            if (p.size() < k)
                p.push(y);
            else{
                if (y > p.top())
                    r.push(-y);
                else
                {
                    r.push(-p.top());
                    p.pop();
                    p.push(y);
                }
                
            }
        }
        else
        {
            if (p.size() < k)
                cout << -1 << endl;
            else
            {
                cout << p.top() << endl;
                p.pop();
                
                if (!r.empty()){
                    p.push(-r.top());
                    r.pop();
                }
            }
            
        }
        
        

    };



    return 0;
}
0