結果

問題 No.626 Randomized 01 Knapsack
ユーザー ikdikd
提出日時 2017-12-15 22:59:22
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 683 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 95,824 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 17:38:02
合計ジャッジ時間 3,119 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 3 ms
4,384 KB
testcase_09 WA -
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 7 ms
4,376 KB
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 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

  int n; long wmax; rd(n, wmax);
  alias T=Tuple!(long, "v", long, "w");
  auto a=new T[](n);
  foreach(i; 0..n) rd(a[i].v, a[i].w);

  sort!((x, y)=>((1.*x.v/x.w)>(1.*y.v/y.w)))(a);
  long vsum=0, wsum=0;
  foreach(e; a){
    if((wsum+e.w)<=wmax){
      vsum+=e.v;
      wsum+=e.w;
    }
  }

  writeln(vsum);
}

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));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) stderr.write(e, " ");
  stderr.writeln();
}
0