結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 76 ms
4,380 KB
testcase_04 AC 84 ms
5,480 KB
testcase_05 AC 51 ms
5,420 KB
testcase_06 AC 48 ms
5,448 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 33 ms
4,440 KB
testcase_13 AC 33 ms
4,416 KB
testcase_14 AC 33 ms
4,540 KB
testcase_15 AC 38 ms
4,388 KB
testcase_16 AC 32 ms
4,416 KB
testcase_17 AC 43 ms
4,604 KB
testcase_18 AC 46 ms
4,732 KB
testcase_19 AC 56 ms
4,700 KB
testcase_20 AC 56 ms
4,920 KB
testcase_21 AC 62 ms
4,780 KB
testcase_22 AC 63 ms
4,908 KB
testcase_23 AC 68 ms
4,820 KB
testcase_24 AC 71 ms
5,108 KB
testcase_25 AC 78 ms
5,116 KB
testcase_26 AC 82 ms
5,096 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,388 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 30 ms
4,564 KB
testcase_31 AC 33 ms
4,548 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 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;
        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