結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-04 10:58:01
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,328 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 266,760 KB
最終ジャッジ日時 2023-08-16 12:46:29
合計ジャッジ時間 68,831 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,280 KB
testcase_01 AC 72 ms
76,024 KB
testcase_02 AC 85 ms
76,432 KB
testcase_03 AC 77 ms
76,464 KB
testcase_04 AC 75 ms
75,864 KB
testcase_05 AC 71 ms
71,420 KB
testcase_06 AC 88 ms
76,632 KB
testcase_07 AC 76 ms
75,892 KB
testcase_08 AC 84 ms
76,420 KB
testcase_09 AC 150 ms
78,896 KB
testcase_10 AC 128 ms
78,428 KB
testcase_11 AC 127 ms
77,836 KB
testcase_12 AC 689 ms
110,068 KB
testcase_13 AC 1,693 ms
133,080 KB
testcase_14 AC 397 ms
95,812 KB
testcase_15 AC 331 ms
94,972 KB
testcase_16 AC 443 ms
99,184 KB
testcase_17 AC 530 ms
90,376 KB
testcase_18 AC 72 ms
71,528 KB
testcase_19 AC 73 ms
71,384 KB
testcase_20 AC 71 ms
71,564 KB
testcase_21 AC 128 ms
78,380 KB
testcase_22 AC 108 ms
77,248 KB
testcase_23 AC 115 ms
77,968 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 AC 72 ms
71,300 KB
testcase_31 AC 71 ms
71,388 KB
testcase_32 AC 113 ms
77,856 KB
testcase_33 AC 122 ms
77,744 KB
testcase_34 AC 142 ms
80,704 KB
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
testcase_45 TLE -
testcase_46 TLE -
testcase_47 TLE -
testcase_48 TLE -
testcase_49 TLE -
testcase_50 TLE -
testcase_51 TLE -
testcase_52 AC 1,716 ms
224,608 KB
testcase_53 TLE -
testcase_54 AC 1,271 ms
245,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main1(n,k,pd):
    # 値段高い順にピザを買うかどうか決める。無料チケットを一枚得られる。
    # dp[i,j,s]:i枚目の購入判断が終わったとき、支払い総額がj円で無料チケットがs枚あるときの最大おいしさ
    # dp[i,j]:ある枚目の購入判断が終わったとき、支払い総額がi円で無料チケットがj枚あるときの最大おいしさ
    # チケット貰った瞬間使うのが最適なのでj<2で考えればよい
    pd.sort(key=lambda x:x[0],reverse=True)
    dp=[[-1]*2 for _ in range(k+1)]
    dp[0][0]=0
    for _,(p,d) in enumerate(pd):
        ndp=[[-1]*2 for _ in range(k+1)]
        for i in range(k+1):
            for j in range(2):
                if dp[i][j]<0:continue
                # 買う
                if i+p<=k:
                    ndp[i+p][min(1,j+1)]=max(ndp[i+p][min(1,j+1)],dp[i][j]+d)
                # 買わない
                ndp[i][j]=max(ndp[i][j],dp[i][j])
                # チケット使う
                if j!=0:
                    ndp[i][j-1]=max(ndp[i][j-1],dp[i][j]+d)
        dp=ndp
    return max([max(dp[i]) for i in range(k+1)])

if __name__=='__main__':
    n,k=map(int,input().split())
    pd=[list(map(int,input().split())) for _ in range(n)]
    ret1=main1(n,k,pd)
    print(ret1)
0