結果

問題 No.1858 Gorgeous Knapsack
ユーザー simansiman
提出日時 2022-02-27 19:43:47
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 334 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 11,340 KB
実行使用メモリ 19,912 KB
最終ジャッジ日時 2023-09-19 06:58:37
合計ジャッジ時間 13,094 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,356 KB
testcase_01 AC 82 ms
15,268 KB
testcase_02 AC 83 ms
15,208 KB
testcase_03 AC 84 ms
15,140 KB
testcase_04 WA -
testcase_05 AC 106 ms
15,264 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 83 ms
15,132 KB
testcase_15 WA -
testcase_16 AC 85 ms
15,212 KB
testcase_17 AC 84 ms
15,208 KB
testcase_18 AC 83 ms
15,160 KB
testcase_19 AC 85 ms
15,216 KB
testcase_20 WA -
testcase_21 AC 85 ms
15,344 KB
testcase_22 AC 84 ms
15,372 KB
testcase_23 AC 85 ms
15,136 KB
testcase_24 AC 149 ms
15,132 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 374 ms
15,432 KB
testcase_28 WA -
testcase_29 AC 91 ms
15,432 KB
testcase_30 AC 92 ms
15,348 KB
testcase_31 AC 91 ms
15,504 KB
testcase_32 AC 92 ms
15,272 KB
testcase_33 AC 96 ms
15,444 KB
testcase_34 TLE -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
J = N.times.map { gets.split.map(&:to_i) }
J.sort_by! { |v, w| -v }

dp = Array.new(M + 1, 0)
dp2 = Array.new(M + 1, 0)

J.each do |v, w|
  (M - w).downto(0) do |i|
    nw = i + w

    if dp[nw] < (dp2[i] + v) * v
      dp[nw] = (dp2[i] + v) * v
      dp2[nw] = dp2[i] + v
    end
  end
end

puts dp.max
0