結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-04 11:01:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,469 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 247,300 KB
最終ジャッジ日時 2023-08-16 12:46:38
合計ジャッジ時間 6,924 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
75,908 KB
testcase_01 AC 72 ms
71,468 KB
testcase_02 AC 89 ms
76,564 KB
testcase_03 AC 77 ms
75,492 KB
testcase_04 AC 73 ms
71,260 KB
testcase_05 AC 72 ms
71,196 KB
testcase_06 AC 83 ms
76,644 KB
testcase_07 AC 73 ms
71,224 KB
testcase_08 AC 83 ms
76,412 KB
testcase_09 AC 166 ms
79,304 KB
testcase_10 AC 137 ms
78,384 KB
testcase_11 AC 135 ms
78,168 KB
testcase_12 AC 1,385 ms
155,036 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
権限があれば一括ダウンロードができます

ソースコード

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
    price_list=set([0])
    for _,(p,d) in enumerate(pd):
        ndp=[[-1]*2 for _ in range(k+1)]
        price_list_add=set()
        for i in price_list:
            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)
                    price_list_add.add(i+p)
                # 買わない
                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
        price_list=price_list|price_list_add
    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