結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー brthyyjp
提出日時 2021-04-21 14:58:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,042 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 268,928 KB
最終ジャッジ日時 2024-07-04 05:57:21
合計ジャッジ時間 10,661 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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

def main():
    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
        #print(dp)
    ans = -INF
    for i in range(k+1):
        for j in range(2):
            ans = max(ans, dp[i][j])
    print(ans)

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