結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
コンテスト
ユーザー brthyyjp
提出日時 2021-04-21 14:57:20
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 857 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 294 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 222,592 KB
最終ジャッジ日時 2026-03-25 14:06:12
合計ジャッジ時間 61,606 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37 TLE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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