結果
問題 | No.649 ここでちょっとQK! |
ユーザー |
![]() |
提出日時 | 2018-02-10 20:03:30 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 225 ms / 3,000 ms |
コード長 | 1,071 bytes |
コンパイル時間 | 1,074 ms |
コンパイル使用メモリ | 126,484 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 23:51:47 |
合計ジャッジ時間 | 5,935 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
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++) { 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; } } } } }