結果

問題 No.617 Nafmo、買い出しに行く
ユーザー simansiman
提出日時 2020-08-10 09:06:26
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,356 ms / 2,000 ms
コード長 271 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 27,776 KB
最終ジャッジ日時 2024-04-16 03:00:43
合計ジャッジ時間 11,030 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
14,720 KB
testcase_01 AC 92 ms
12,160 KB
testcase_02 AC 278 ms
14,976 KB
testcase_03 AC 551 ms
17,536 KB
testcase_04 AC 128 ms
12,928 KB
testcase_05 AC 642 ms
20,992 KB
testcase_06 AC 1,356 ms
27,648 KB
testcase_07 AC 1,352 ms
27,776 KB
testcase_08 AC 93 ms
12,160 KB
testcase_09 AC 92 ms
12,288 KB
testcase_10 AC 626 ms
23,296 KB
testcase_11 AC 670 ms
25,600 KB
testcase_12 AC 891 ms
19,328 KB
testcase_13 AC 649 ms
16,384 KB
testcase_14 AC 725 ms
17,664 KB
testcase_15 AC 94 ms
12,288 KB
testcase_16 AC 95 ms
12,160 KB
testcase_17 AC 94 ms
12,032 KB
testcase_18 AC 92 ms
12,288 KB
testcase_19 AC 93 ms
12,160 KB
testcase_20 AC 92 ms
12,160 KB
testcase_21 AC 94 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)
A = N.times.map { gets.to_i }

dp = Array.new(K + 1, false)
dp[0] = true
ans = 0

A.each do |a|
  ans.downto(0) do |v|
    next unless dp[v]

    nv = v + a

    next if K < nv

    dp[nv] = true
    ans = nv if ans < nv
  end
end

puts ans
0