結果

問題 No.649 ここでちょっとQK!
ユーザー noriocnorioc
提出日時 2018-02-10 19:59:16
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,053 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 112,352 KB
実行使用メモリ 5,468 KB
最終ジャッジ日時 2023-09-03 18:42:57
合計ジャッジ時間 6,751 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 WA -
testcase_03 AC 162 ms
4,380 KB
testcase_04 AC 204 ms
5,464 KB
testcase_05 WA -
testcase_06 AC 194 ms
5,468 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,384 KB
testcase_35 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

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);
    auto q2 = new BinaryHeap!(Array!long);
    for (int i = 0; i < q; i++) {
        auto xs = reads!long;
        if (xs.length > 1) {
            q1.insert(xs[1]);
            if (q1.length > k) {
                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