結果

問題 No.527 ナップサック容量問題
ユーザー cielciel
提出日時 2017-06-13 21:54:19
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 238 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 11,840 KB
実行使用メモリ 16,816 KB
最終ジャッジ日時 2023-10-24 21:51:28
合計ジャッジ時間 7,209 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
16,028 KB
testcase_01 RE -
testcase_02 AC 78 ms
16,028 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 128 ms
16,288 KB
testcase_06 AC 298 ms
16,552 KB
testcase_07 AC 217 ms
16,552 KB
testcase_08 AC 111 ms
16,064 KB
testcase_09 AC 79 ms
16,028 KB
testcase_10 AC 290 ms
16,564 KB
testcase_11 AC 170 ms
16,288 KB
testcase_12 AC 131 ms
16,284 KB
testcase_13 AC 320 ms
16,304 KB
testcase_14 AC 116 ms
16,284 KB
testcase_15 AC 160 ms
16,288 KB
testcase_16 AC 79 ms
16,028 KB
testcase_17 AC 125 ms
16,288 KB
testcase_18 AC 144 ms
16,288 KB
testcase_19 AC 78 ms
16,028 KB
testcase_20 AC 107 ms
16,064 KB
testcase_21 AC 353 ms
16,592 KB
testcase_22 AC 221 ms
16,552 KB
testcase_23 AC 301 ms
16,552 KB
testcase_24 AC 91 ms
16,028 KB
testcase_25 RE -
testcase_26 AC 174 ms
16,288 KB
testcase_27 AC 185 ms
16,288 KB
testcase_28 RE -
testcase_29 AC 375 ms
16,816 KB
testcase_30 AC 83 ms
16,028 KB
testcase_31 AC 78 ms
16,028 KB
testcase_32 AC 79 ms
16,028 KB
testcase_33 AC 78 ms
16,028 KB
testcase_34 AC 79 ms
16,024 KB
testcase_35 AC 165 ms
16,288 KB
testcase_36 RE -
testcase_37 AC 129 ms
16,288 KB
testcase_38 AC 143 ms
16,288 KB
testcase_39 AC 141 ms
16,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
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
p idx=bag.index(v+1)
idx=(idx...bag.size).find{|i|bag[i]>v+1}
puts idx ? idx-1 : :inf
0