結果

問題 No.649 ここでちょっとQK!
ユーザー nebukuro09nebukuro09
提出日時 2018-02-09 22:45:17
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 175 ms / 3,000 ms
コード長 1,216 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 133,588 KB
実行使用メモリ 8,928 KB
最終ジャッジ日時 2024-06-12 23:49:29
合計ジャッジ時間 6,266 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;


void main() {
    auto s = readln.split.map!(to!int);
    auto Q = s[0];
    auto K = s[1];
    auto small = new BinaryHeap!(Array!long, "a < b");
    auto large = new BinaryHeap!(Array!long, "a > b");

    while (Q--) {
        auto q = readln.split.map!(to!long);
        auto t = q[0];
        if (t == 1) {
            auto v = q[1];
            if (small.length < K) {
                small.insert(v);
            } else if (small.front > v) {
                auto w = small.front;
                small.removeFront;
                small.insert(v);
                large.insert(w);
            } else {
                large.insert(v);
            }
        } else {
            if (small.length < K) {
                writeln(-1);
                continue;
            }
            small.front.writeln;
            small.removeFront;
            if (large.length > 0) {
                small.insert(large.front);
                large.removeFront;
            }
        }
    }
}
0