結果

問題 No.1858 Gorgeous Knapsack
ユーザー norioc
提出日時 2025-03-26 02:51:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 516 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 82,956 KB
実行使用メモリ 85,856 KB
最終ジャッジ日時 2025-03-26 02:51:26
合計ジャッジ時間 4,225 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other TLE * 1 -- * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
items = []
for i in range(N):
    V, W = map(int, input().split())
    items.append((V, W))


def knapsack(min_v):
    dp = [-1] * (M+1)
    dp[0] = 0
    for v, w in items:
        if v < min_v: continue
        for i in reversed(range(M)):
            if dp[i] == -1: continue
            if i+w > M: continue
            dp[i+w] = max(dp[i+w], dp[i] + v)

    return max(dp)


vset = set(v for v, _ in items)
ans = 0
for v in vset:
    ans = max(ans, v * knapsack(v))

print(ans)
0