結果

問題 No.1858 Gorgeous Knapsack
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-15 04:13:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 75,900 KB
最終ジャッジ日時 2023-10-21 15:43:21
合計ジャッジ時間 6,567 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,344 KB
testcase_01 AC 39 ms
53,344 KB
testcase_02 AC 38 ms
53,344 KB
testcase_03 AC 41 ms
59,280 KB
testcase_04 AC 176 ms
75,748 KB
testcase_05 AC 66 ms
75,228 KB
testcase_06 AC 193 ms
75,764 KB
testcase_07 AC 117 ms
75,800 KB
testcase_08 AC 251 ms
75,796 KB
testcase_09 AC 389 ms
75,900 KB
testcase_10 AC 144 ms
75,888 KB
testcase_11 AC 211 ms
75,896 KB
testcase_12 AC 319 ms
75,892 KB
testcase_13 AC 72 ms
75,884 KB
testcase_14 AC 43 ms
61,492 KB
testcase_15 AC 40 ms
59,276 KB
testcase_16 AC 40 ms
59,284 KB
testcase_17 AC 35 ms
53,344 KB
testcase_18 AC 35 ms
53,344 KB
testcase_19 AC 35 ms
53,344 KB
testcase_20 AC 38 ms
53,344 KB
testcase_21 AC 36 ms
53,344 KB
testcase_22 AC 34 ms
53,344 KB
testcase_23 AC 33 ms
53,344 KB
testcase_24 AC 85 ms
75,212 KB
testcase_25 AC 229 ms
75,880 KB
testcase_26 AC 225 ms
75,788 KB
testcase_27 AC 211 ms
75,780 KB
testcase_28 AC 137 ms
75,844 KB
testcase_29 AC 51 ms
64,396 KB
testcase_30 AC 52 ms
66,460 KB
testcase_31 AC 50 ms
64,400 KB
testcase_32 AC 47 ms
64,400 KB
testcase_33 AC 53 ms
66,444 KB
testcase_34 AC 299 ms
75,892 KB
testcase_35 AC 147 ms
75,756 KB
testcase_36 AC 306 ms
75,860 KB
testcase_37 AC 34 ms
53,344 KB
testcase_38 AC 44 ms
64,364 KB
testcase_39 AC 38 ms
59,108 KB
testcase_40 AC 148 ms
75,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def main():

    n, m = map(int, input().split())
    VW = []
    for i in range(n):
        v, w = map(int, input().split())
        VW.append((v, w))
    VW.sort(key=lambda x: -x[0])
    dp = [-1]*(m+1)
    dp[0] = 0
    ans = 0
    for v, w in VW:
        for i in reversed(range(m+1)):
            if dp[i] == -1:
                continue
            if i+w <= m:
                ans = max(ans, (dp[i]+v)*v)
                dp[i+w] = max(dp[i+w], dp[i]+v)
    print(ans)

if __name__ == '__main__':
    main()
0