結果

問題 No.649 ここでちょっとQK!
ユーザー norioc
提出日時 2018-02-10 20:19:34
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 82 ms / 3,000 ms
コード長 1,312 bytes
コンパイル時間 915 ms
コンパイル使用メモリ 126,480 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 23:52:03
合計ジャッジ時間 3,719 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto qk = readints;
    int q = qk[0], k = qk[1];

    auto q1 = new BinaryHeap!(Array!long, "a < b");
    auto q2 = new BinaryHeap!(Array!long, "a > b");
    for (int i = 0; i < q; i++) {
        string s = readln;
        if (s[0] == '1') {
            long x = s[2..$-1].to!long;

            if (q1.length < k) {
                q1.insert(x);
            }
            else {
                if (q1.front <= x) {
                    q2.insert(x);
                }
                else {
                    q1.insert(x);
                    q2.insert(q1.front);
                    q1.popFront;
                }
            }
        }
        else {
            if (q1.length < k) {
                writeln(-1);
            }
            else {
                writeln(q1.front);
                q1.popFront;
                if (q2.length > 0) {
                    q1.insert(q2.front);
                    q2.popFront;
                }
            }
        }
   }
}
0