結果

問題 No.527 ナップサック容量問題
ユーザー cielciel
提出日時 2017-06-13 21:56:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 243 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 11,948 KB
実行使用メモリ 16,816 KB
最終ジャッジ日時 2023-10-24 21:52:32
合計ジャッジ時間 7,934 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
16,028 KB
testcase_01 AC 88 ms
16,028 KB
testcase_02 AC 88 ms
16,028 KB
testcase_03 AC 91 ms
16,028 KB
testcase_04 AC 91 ms
16,028 KB
testcase_05 AC 137 ms
16,288 KB
testcase_06 AC 307 ms
16,552 KB
testcase_07 AC 227 ms
16,552 KB
testcase_08 AC 121 ms
16,064 KB
testcase_09 AC 90 ms
16,028 KB
testcase_10 AC 298 ms
16,564 KB
testcase_11 AC 179 ms
16,288 KB
testcase_12 AC 141 ms
16,288 KB
testcase_13 AC 332 ms
16,552 KB
testcase_14 AC 124 ms
16,288 KB
testcase_15 AC 170 ms
16,288 KB
testcase_16 AC 89 ms
16,028 KB
testcase_17 AC 135 ms
16,284 KB
testcase_18 AC 155 ms
16,288 KB
testcase_19 AC 88 ms
16,028 KB
testcase_20 AC 118 ms
16,064 KB
testcase_21 AC 364 ms
16,592 KB
testcase_22 AC 230 ms
16,552 KB
testcase_23 AC 312 ms
16,552 KB
testcase_24 AC 101 ms
16,028 KB
testcase_25 AC 199 ms
16,288 KB
testcase_26 AC 183 ms
16,288 KB
testcase_27 AC 200 ms
16,288 KB
testcase_28 AC 170 ms
16,288 KB
testcase_29 AC 383 ms
16,816 KB
testcase_30 AC 88 ms
16,028 KB
testcase_31 AC 88 ms
16,028 KB
testcase_32 AC 89 ms
16,028 KB
testcase_33 AC 89 ms
16,028 KB
testcase_34 AC 88 ms
16,028 KB
testcase_35 AC 175 ms
16,288 KB
testcase_36 AC 88 ms
16,028 KB
testcase_37 AC 140 ms
16,288 KB
testcase_38 AC 154 ms
16,288 KB
testcase_39 AC 151 ms
16,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

bag=[1]
s=0
gets.to_i.times{
	v,w=gets.split.map(&:to_i)
	(s+=w).downto(w){|i|
		bag[i]=[bag[i]||0,(bag[i-w]||0)+v].max
	}
}
v=gets.to_i
idx=bag.index(v+1)
p idx<1 ? 1 : idx
idx=(idx...bag.size).find{|i|(bag[i]||0)>v+1}
puts idx ? idx-1 : :inf
0