結果

問題 No.1947 質より種類数
ユーザー H20
提出日時 2022-04-10 18:44:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 592 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 77,304 KB
最終ジャッジ日時 2024-12-21 06:51:01
合計ジャッジ時間 8,192 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

N,V,C = map(int, input().split())
VW = [list(map(int, input().split())) for _ in range(N)]
if not (1<=N<=5000 and 1<=V<=5000 and 1<=C<=5000):
    exit()
for v,w in VW:
    if 1<=v<=5000 and 1<=w<=5000:
        continue
    exit()

DP = [0]*(V+1)
for v,w in VW:
    w+=C
    for i in reversed(range(V)):
        if DP[i]>0 and i+v<=V and DP[i+v]<DP[i]+w:
            DP[i+v]=DP[i]+w
    if v<=V and DP[v]<w:
        DP[v]=w
for v,w in VW:
    for i in range(V):
        if DP[i]>0 and i+v<=V and DP[i+v]<DP[i]+w:
            DP[i+v]=DP[i]+w
print(max(DP))
0