結果

問題 No.649 ここでちょっとQK!
ユーザー ikdikd
提出日時 2018-02-12 17:32:28
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 233 ms / 3,000 ms
コード長 896 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 105,952 KB
実行使用メモリ 5,452 KB
最終ジャッジ日時 2023-09-03 18:45:18
合計ジャッジ時間 6,283 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 184 ms
4,380 KB
testcase_04 AC 233 ms
5,452 KB
testcase_05 AC 197 ms
5,408 KB
testcase_06 AC 197 ms
5,412 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 107 ms
4,472 KB
testcase_13 AC 108 ms
4,500 KB
testcase_14 AC 107 ms
4,536 KB
testcase_15 AC 112 ms
4,544 KB
testcase_16 AC 108 ms
4,516 KB
testcase_17 AC 127 ms
4,660 KB
testcase_18 AC 139 ms
4,664 KB
testcase_19 AC 154 ms
4,716 KB
testcase_20 AC 166 ms
4,844 KB
testcase_21 AC 175 ms
4,888 KB
testcase_22 AC 189 ms
4,892 KB
testcase_23 AC 199 ms
4,872 KB
testcase_24 AC 213 ms
5,148 KB
testcase_25 AC 223 ms
5,168 KB
testcase_26 AC 233 ms
5,112 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 92 ms
4,604 KB
testcase_31 AC 99 ms
4,564 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.container;

  int q, k; rd(q, k);
  auto qmax=new BinaryHeap!(Array!(long))(),
       qmin=new BinaryHeap!(Array!(long), "a>b")();
  while(q--){
    auto args=readln.split.to!(long[]);
    if(args[0]==1){
      auto v=args[1];
      if(qmax.length<k) qmax.insert(v);
      else if(qmax.front<=v) qmin.insert(v);
      else{qmin.insert(qmax.front); qmax.popFront; qmax.insert(v);}
    }else{
      if(qmax.length>=k){
        writeln(qmax.front);
        qmax.popFront;
        if(qmax.length<k && qmin.length>0){
          qmax.insert(qmin.front);
          qmin.popFront;
        }
      }else{
        writeln(-1);
      }
    }
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0