結果

問題 No.649 ここでちょっとQK!
ユーザー noriocnorioc
提出日時 2018-02-10 20:15:51
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 96 ms / 3,000 ms
コード長 1,135 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 113,084 KB
実行使用メモリ 5,436 KB
最終ジャッジ日時 2023-09-03 18:43:39
合計ジャッジ時間 4,095 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 78 ms
4,380 KB
testcase_04 AC 79 ms
5,428 KB
testcase_05 AC 76 ms
5,372 KB
testcase_06 AC 65 ms
5,436 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 44 ms
4,384 KB
testcase_13 AC 43 ms
4,432 KB
testcase_14 AC 46 ms
4,580 KB
testcase_15 AC 49 ms
4,504 KB
testcase_16 AC 32 ms
4,392 KB
testcase_17 AC 46 ms
4,616 KB
testcase_18 AC 49 ms
4,708 KB
testcase_19 AC 56 ms
4,684 KB
testcase_20 AC 60 ms
4,856 KB
testcase_21 AC 68 ms
4,780 KB
testcase_22 AC 73 ms
4,884 KB
testcase_23 AC 76 ms
4,848 KB
testcase_24 AC 83 ms
5,140 KB
testcase_25 AC 90 ms
5,132 KB
testcase_26 AC 96 ms
5,132 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 42 ms
4,508 KB
testcase_31 AC 37 ms
4,568 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 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, "a < b");
    auto q2 = new BinaryHeap!(Array!long, "a > b");
    for (int i = 0; i < q; i++) {
        string s = readln;
        // auto xs = reads!long;
        if (s[0] == '1') {
            long x = s[2..$-1].to!long;
            q1.insert(x);
            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