結果

問題 No.527 ナップサック容量問題
ユーザー letrangerjpletrangerjp
提出日時 2017-06-10 20:57:57
言語 Ruby
(3.3.0)
結果
AC  
実行時間 896 ms / 2,000 ms
コード長 341 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 11,880 KB
実行使用メモリ 16,356 KB
最終ジャッジ日時 2023-10-24 20:35:59
合計ジャッジ時間 12,796 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
16,064 KB
testcase_01 AC 87 ms
16,064 KB
testcase_02 AC 81 ms
16,064 KB
testcase_03 AC 79 ms
16,064 KB
testcase_04 AC 78 ms
16,064 KB
testcase_05 AC 215 ms
16,120 KB
testcase_06 AC 734 ms
16,328 KB
testcase_07 AC 481 ms
16,324 KB
testcase_08 AC 169 ms
16,088 KB
testcase_09 AC 82 ms
16,064 KB
testcase_10 AC 705 ms
16,324 KB
testcase_11 AC 337 ms
16,324 KB
testcase_12 AC 229 ms
16,324 KB
testcase_13 AC 783 ms
16,340 KB
testcase_14 AC 180 ms
16,116 KB
testcase_15 AC 307 ms
16,324 KB
testcase_16 AC 82 ms
16,064 KB
testcase_17 AC 216 ms
16,120 KB
testcase_18 AC 263 ms
16,324 KB
testcase_19 AC 81 ms
16,064 KB
testcase_20 AC 166 ms
16,088 KB
testcase_21 AC 864 ms
16,332 KB
testcase_22 AC 499 ms
16,324 KB
testcase_23 AC 747 ms
16,324 KB
testcase_24 AC 110 ms
16,064 KB
testcase_25 AC 411 ms
16,324 KB
testcase_26 AC 345 ms
16,324 KB
testcase_27 AC 380 ms
16,324 KB
testcase_28 AC 322 ms
16,320 KB
testcase_29 AC 896 ms
16,356 KB
testcase_30 AC 80 ms
16,064 KB
testcase_31 AC 80 ms
16,064 KB
testcase_32 AC 80 ms
16,064 KB
testcase_33 AC 79 ms
16,064 KB
testcase_34 AC 79 ms
16,064 KB
testcase_35 AC 343 ms
16,324 KB
testcase_36 AC 83 ms
16,064 KB
testcase_37 AC 228 ms
16,324 KB
testcase_38 AC 291 ms
16,324 KB
testcase_39 AC 260 ms
16,324 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
VA, WA = N.times.map{ gets.split.take(2).map(&:to_i)}.sort.transpose
V = gets.to_i

$dp = [0]*(WA.sum+1)

N.times{|i|
  (WA.sum).downto(WA[i]){|ii|
    $dp[ii] = [$dp[ii], $dp[ii - WA[i]] + VA[i]].max
  }
}
# p $dp
min = $dp.bsearch_index{|v|v>=V}
max = $dp.bsearch_index{|v|v>V}
puts [min, 1].max
puts max.nil? ? :inf : max-1
0