結果

問題 No.1858 Gorgeous Knapsack
ユーザー ああいいああいい
提出日時 2022-02-28 12:59:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 78,472 KB
最終ジャッジ日時 2023-09-20 20:30:29
合計ジャッジ時間 6,846 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,564 KB
testcase_01 AC 68 ms
71,300 KB
testcase_02 AC 69 ms
71,260 KB
testcase_03 AC 76 ms
76,080 KB
testcase_04 AC 130 ms
77,632 KB
testcase_05 AC 93 ms
77,044 KB
testcase_06 AC 137 ms
77,784 KB
testcase_07 AC 128 ms
77,800 KB
testcase_08 AC 169 ms
77,924 KB
testcase_09 AC 232 ms
78,012 KB
testcase_10 AC 142 ms
78,044 KB
testcase_11 AC 149 ms
77,944 KB
testcase_12 AC 191 ms
77,980 KB
testcase_13 AC 111 ms
77,796 KB
testcase_14 AC 76 ms
75,844 KB
testcase_15 AC 70 ms
71,276 KB
testcase_16 AC 75 ms
76,028 KB
testcase_17 AC 67 ms
71,272 KB
testcase_18 AC 68 ms
71,296 KB
testcase_19 AC 67 ms
71,100 KB
testcase_20 AC 69 ms
71,508 KB
testcase_21 AC 69 ms
71,296 KB
testcase_22 AC 68 ms
71,448 KB
testcase_23 AC 72 ms
71,352 KB
testcase_24 AC 102 ms
77,020 KB
testcase_25 AC 153 ms
78,080 KB
testcase_26 AC 157 ms
77,576 KB
testcase_27 AC 155 ms
77,996 KB
testcase_28 AC 128 ms
78,000 KB
testcase_29 AC 98 ms
76,824 KB
testcase_30 AC 105 ms
77,824 KB
testcase_31 AC 102 ms
77,640 KB
testcase_32 AC 107 ms
77,704 KB
testcase_33 AC 105 ms
77,768 KB
testcase_34 AC 417 ms
78,100 KB
testcase_35 AC 121 ms
77,936 KB
testcase_36 AC 408 ms
78,472 KB
testcase_37 AC 69 ms
71,380 KB
testcase_38 AC 97 ms
76,896 KB
testcase_39 AC 72 ms
75,708 KB
testcase_40 AC 119 ms
78,120 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()
    tmp = -1
    for j in range(M+1-w):
        if tmp < dp[j]:
            tmp = dp[j]
    if tmp >= 0 and ans < (tmp + v) * v:
        ans = (tmp + v) * v
    for j in range(M+1-w):
        nx[j+w] = max(nx[j+w],dp[j] + v)
    dp = nx
print(ans)
0