結果

問題 No.617 Nafmo、買い出しに行く
ユーザー RyutoRyuto
提出日時 2017-12-18 20:24:48
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 457 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 87,328 KB
実行使用メモリ 77,140 KB
最終ジャッジ日時 2023-08-22 05:51:04
合計ジャッジ時間 3,328 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,288 KB
testcase_01 AC 72 ms
71,024 KB
testcase_02 AC 85 ms
75,372 KB
testcase_03 AC 98 ms
76,424 KB
testcase_04 AC 71 ms
71,248 KB
testcase_05 AC 97 ms
76,336 KB
testcase_06 AC 113 ms
76,340 KB
testcase_07 AC 110 ms
76,548 KB
testcase_08 AC 70 ms
71,212 KB
testcase_09 AC 69 ms
71,176 KB
testcase_10 AC 109 ms
76,464 KB
testcase_11 AC 111 ms
76,480 KB
testcase_12 AC 119 ms
76,596 KB
testcase_13 AC 142 ms
77,140 KB
testcase_14 AC 122 ms
76,592 KB
testcase_15 AC 69 ms
71,272 KB
testcase_16 AC 72 ms
71,176 KB
testcase_17 AC 71 ms
71,200 KB
testcase_18 AC 69 ms
71,084 KB
testcase_19 AC 71 ms
70,892 KB
testcase_20 AC 72 ms
71,024 KB
testcase_21 AC 72 ms
71,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python

indat = [int(x) for x in input().split()]
weights = list()
for i in range(indat[0]):
    x = int(input())
    if x < indat[1]:
        weights.append(x)
    elif x == indat[1]:
        print(x)
        exit()

def rec(i,j):
    if i == len(weights):
        res = 0
    elif j < weights[i]:
        res = rec(i+1,j)
    else:
        res = max(rec(i+1, j), rec(i+1, j-weights[i]) + weights[i])
    return res

print(rec(0, indat[1]))
0