結果

問題 No.1858 Gorgeous Knapsack
ユーザー kept1994kept1994
提出日時 2022-05-06 01:29:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 684 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 275,068 KB
最終ジャッジ日時 2023-09-18 11:48:57
合計ジャッジ時間 10,665 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,348 KB
testcase_01 AC 76 ms
71,092 KB
testcase_02 AC 78 ms
71,232 KB
testcase_03 AC 81 ms
75,796 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 83 ms
75,980 KB
testcase_17 WA -
testcase_18 AC 74 ms
71,500 KB
testcase_19 AC 74 ms
71,476 KB
testcase_20 AC 73 ms
71,312 KB
testcase_21 AC 74 ms
71,296 KB
testcase_22 AC 75 ms
71,420 KB
testcase_23 AC 73 ms
71,240 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 117 ms
78,316 KB
testcase_33 WA -
testcase_34 AC 676 ms
274,928 KB
testcase_35 AC 417 ms
274,960 KB
testcase_36 AC 668 ms
275,036 KB
testcase_37 AC 75 ms
71,444 KB
testcase_38 AC 116 ms
79,264 KB
testcase_39 AC 79 ms
75,564 KB
testcase_40 AC 414 ms
275,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys

def main():
    N, M = map(int, input().split())
    INF = 10 ** 18
    dp = [[-INF for _ in range(M + 1)] for _ in range(N + 1)]
    dp[0][0] = 0
    l = sorted([tuple(map(int, input().split())) for _ in range(N)], reverse=True)
    ans = 0
    for i in range(N):
        v, w = l[i]
        for j in range(M):
            if dp[i][j] == -INF:
                continue
            # 選ばない
            dp[i + 1][j] = dp[i][j]
            # 選ぶ
            if j + w < M + 1:
                dp[i + 1][j + w] = dp[i][j] + v
                ans = max(ans, v * dp[i + 1][j + w])
    print(ans)
    return

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