結果
| 問題 |
No.626 Randomized 01 Knapsack
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2017-12-15 22:59:22 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 683 bytes |
| コンパイル時間 | 815 ms |
| コンパイル使用メモリ | 112,164 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 23:08:09 |
| 合計ジャッジ時間 | 2,084 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 19 |
ソースコード
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();
}
ikd