結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー brthyyjp
提出日時 2021-04-21 14:57:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 857 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 226,688 KB
最終ジャッジ日時 2024-07-04 05:57:10
合計ジャッジ時間 11,411 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 TLE * 2 -- * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

n, k = map(int, input().split())
PD = []
for i in range(n):
    p, d = map(int, input().split())
    PD.append((p,d))

PD.sort(key=lambda x: -x[0])
INF = 10**18
dp = [[-INF]*2 for i in range(k+1)]
dp[0][0] = 0
for p, d in PD:
    nx = [[-INF]*2 for i in range(k+1)]
    for i in range(k+1):
        for j in range(2):
            nx[i][j] = max(nx[i][j], dp[i][j])
    for i in range(k+1):
        for j in range(2):
            if dp[i][j] == -INF:
                continue
            if j == 0:
                if i+p <= k:
                    nx[i+p][1] = max(nx[i+p][1], dp[i][j]+d)
            else:
                nx[i][0] = max(nx[i][0], dp[i][j]+d)
    dp = nx

ans = -INF
for i in range(k+1):
    for j in range(2):
        ans = max(ans, dp[i][j])
print(ans)
0