結果

問題 No.649 ここでちょっとQK!
ユーザー tecchaxn
提出日時 2018-02-10 12:04:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 251 ms / 3,000 ms
コード長 1,016 bytes
コンパイル時間 1,346 ms
コンパイル使用メモリ 163,504 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-10-13 05:13:31
合計ジャッジ時間 5,420 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
#define INF 1e18
#define MOD 1000000007
#define SIZE 100005

using namespace std;
typedef pair<int,int> P;

//-----------------------------------------------------------------------

int Q,K;
multiset<int> A,B;

signed main()
{   
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>Q>>K;
    REP(i,Q){
        int x; cin>>x;
        if(x==1)
        {
            int v; cin>>v;
            A.insert(v);
            if(A.size()>K){
                B.insert(*A.rbegin());
                A.erase(A.find(*A.rbegin()));
            }
        }
        else
        {
            if(A.size()<K) cout<<-1<<endl;
            else{
                cout<<*A.rbegin()<<endl;
                A.erase(A.find(*A.rbegin()));
                if(!B.empty()){
                    A.insert(*B.begin());
                    B.erase(B.find(*B.begin()));
                }
            }
        }
    }
}
0