結果

問題 No.649 ここでちょっとQK!
コンテスト
ユーザー zelda_master
提出日時 2026-10-19 00:40:07
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 45 ms / 3,000 ms
+ 515µs
コード長 1,140 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,144 ms
コンパイル使用メモリ 189,532 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-10-19 00:40:14
合計ジャッジ時間 6,608 ms
ジャッジサーバーID
(参考情報)
judge6_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
priority_queue<LL, vector<LL>, greater<LL>> sm;
priority_queue<LL> bg;
int main()
{
    int q, k;
    scanf("%d%d", &q, &k);
    while (q--)
    {
        int id;
        scanf("%d", &id);
        if (id == 1)
        {
            LL xx;
            scanf("%lld", &xx);
            if (bg.size() < k)
            {
                bg.push(xx);
            }
            else
            {
                if (xx < bg.top())
                {
                    sm.push(bg.top());
                    bg.pop();
                    bg.push(xx);
                } 
                else
                {
                    sm.push(xx);
                }
            }
        }
        else
        {
            if (bg.size() < k)
            {
                puts("-1");
            }
            else
            {
                printf("%lld\n", bg.top());
                bg.pop();
                if (!sm.empty())
                {
                    bg.push(sm.top());
                    sm.pop();
                }
            }
        }
    }
    return 0;
}
0