結果

問題 No.1858 Gorgeous Knapsack
ユーザー ああいいああいい
提出日時 2022-02-28 12:46:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 78,412 KB
最終ジャッジ日時 2023-09-20 20:15:50
合計ジャッジ時間 7,065 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,496 KB
testcase_01 AC 72 ms
71,444 KB
testcase_02 AC 74 ms
71,224 KB
testcase_03 AC 80 ms
76,080 KB
testcase_04 AC 152 ms
77,648 KB
testcase_05 AC 102 ms
76,816 KB
testcase_06 AC 150 ms
78,112 KB
testcase_07 AC 129 ms
77,656 KB
testcase_08 AC 195 ms
78,320 KB
testcase_09 AC 249 ms
77,864 KB
testcase_10 AC 144 ms
77,640 KB
testcase_11 AC 151 ms
77,708 KB
testcase_12 AC 222 ms
77,956 KB
testcase_13 AC 113 ms
77,684 KB
testcase_14 AC 77 ms
76,040 KB
testcase_15 AC 73 ms
71,424 KB
testcase_16 AC 78 ms
76,148 KB
testcase_17 AC 70 ms
71,260 KB
testcase_18 AC 73 ms
71,612 KB
testcase_19 AC 70 ms
71,532 KB
testcase_20 AC 71 ms
71,428 KB
testcase_21 AC 70 ms
71,524 KB
testcase_22 AC 71 ms
71,264 KB
testcase_23 AC 72 ms
71,384 KB
testcase_24 AC 101 ms
77,264 KB
testcase_25 AC 167 ms
77,980 KB
testcase_26 AC 154 ms
77,916 KB
testcase_27 AC 166 ms
77,808 KB
testcase_28 AC 130 ms
78,256 KB
testcase_29 AC 105 ms
77,708 KB
testcase_30 AC 108 ms
78,020 KB
testcase_31 AC 107 ms
77,948 KB
testcase_32 AC 109 ms
77,776 KB
testcase_33 AC 109 ms
77,624 KB
testcase_34 AC 402 ms
78,376 KB
testcase_35 AC 137 ms
78,060 KB
testcase_36 AC 396 ms
78,412 KB
testcase_37 AC 72 ms
71,068 KB
testcase_38 AC 102 ms
77,888 KB
testcase_39 AC 76 ms
75,852 KB
testcase_40 AC 130 ms
78,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
l = []
for i in range(N):
    v,w = map(int,input().split())
    l.append((v,w))
l.sort(reverse = True,key = lambda s:s[0])
#dp = [[0] * (M+1) for _ in range(N+1)]
dp = [0] * (M+1)
ans = 0
for i in range(N):
    v,w = l[i]
    nx = dp.copy()
    for j in range(M+1):
        if j + w <= M:
            tmp = (dp[j] + v) * v
            if tmp > ans:
                ans = tmp
        else:
            break
    for j in range(M+1):
        if j + w <= M:
            nx[j+w] = max(nx[j+w],dp[j] + v)
        else:
            break
    dp = nx
print(ans)
0