結果

問題 No.649 ここでちょっとQK!
ユーザー T1610
提出日時 2018-02-13 01:51:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,360 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 173,736 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-27 08:06:28
合計ジャッジ時間 6,812 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 17 WA * 15
権限があれば一括ダウンロードができます

ソースコード

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);
                }
            } 
        }
        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