結果

問題 No.1858 Gorgeous Knapsack
ユーザー simansiman
提出日時 2022-02-27 20:03:44
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 407 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 11,492 KB
実行使用メモリ 215,116 KB
最終ジャッジ日時 2023-09-19 07:22:15
合計ジャッジ時間 24,280 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,240 KB
testcase_01 AC 81 ms
15,124 KB
testcase_02 AC 81 ms
15,120 KB
testcase_03 AC 92 ms
15,612 KB
testcase_04 AC 884 ms
52,580 KB
testcase_05 AC 227 ms
22,484 KB
testcase_06 AC 1,049 ms
61,108 KB
testcase_07 AC 591 ms
41,052 KB
testcase_08 AC 1,493 ms
81,684 KB
testcase_09 TLE -
testcase_10 AC 688 ms
44,004 KB
testcase_11 AC 1,210 ms
66,924 KB
testcase_12 AC 1,958 ms
103,524 KB
testcase_13 AC 195 ms
21,808 KB
testcase_14 AC 83 ms
15,128 KB
testcase_15 AC 83 ms
15,140 KB
testcase_16 AC 83 ms
15,252 KB
testcase_17 AC 83 ms
15,244 KB
testcase_18 AC 84 ms
15,208 KB
testcase_19 AC 82 ms
15,228 KB
testcase_20 AC 83 ms
15,208 KB
testcase_21 AC 82 ms
15,072 KB
testcase_22 AC 82 ms
15,200 KB
testcase_23 AC 82 ms
15,236 KB
testcase_24 AC 380 ms
30,008 KB
testcase_25 AC 1,744 ms
97,188 KB
testcase_26 AC 1,456 ms
80,784 KB
testcase_27 AC 1,394 ms
78,136 KB
testcase_28 AC 943 ms
57,800 KB
testcase_29 AC 90 ms
15,648 KB
testcase_30 AC 93 ms
15,636 KB
testcase_31 AC 92 ms
15,224 KB
testcase_32 AC 89 ms
15,224 KB
testcase_33 AC 100 ms
16,004 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(N + 1) { Array.new(M + 1, 0) }
ans = 0

J.each_with_index do |(v, w), i|
  M.downto(0) do |j|
    dp[i + 1][j] = dp[i][j]
    nw = j + w
    nv = dp[i][j] + v
    next if nw > M

    if dp[i + 1][nw] < nv
      dp[i + 1][nw] = nv
      ans = nv * v if ans < nv * v
    end
  end
end

puts ans
0