結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
335,424 KB
testcase_01 AC 69 ms
71,276 KB
testcase_02 AC 86 ms
76,288 KB
testcase_03 AC 70 ms
71,316 KB
testcase_04 AC 72 ms
71,404 KB
testcase_05 AC 71 ms
71,480 KB
testcase_06 AC 80 ms
76,460 KB
testcase_07 AC 70 ms
71,444 KB
testcase_08 AC 71 ms
71,388 KB
testcase_09 AC 131 ms
77,916 KB
testcase_10 AC 115 ms
77,480 KB
testcase_11 AC 113 ms
77,596 KB
testcase_12 AC 852 ms
173,128 KB
testcase_13 TLE -
testcase_14 AC 569 ms
137,328 KB
testcase_15 AC 240 ms
86,720 KB
testcase_16 AC 323 ms
87,396 KB
testcase_17 AC 368 ms
83,480 KB
testcase_18 AC 69 ms
71,296 KB
testcase_19 AC 70 ms
71,400 KB
testcase_20 AC 71 ms
71,344 KB
testcase_21 AC 117 ms
77,800 KB
testcase_22 AC 108 ms
77,500 KB
testcase_23 AC 117 ms
77,996 KB
testcase_24 TLE -
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 maxb(x,y):
    if x>y:return x
    return y
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)
    dp0=[-1]*(k+1)
    dp1=[-1]*(k+1)
    dp0[0]=0
    price_list=set([0])
    price_list_add=set()
    for p,d in pd:
        update0=[]
        update1=[]
        for i in price_list:
            # チケットなし
            if dp0[i]>=0:
                if i+p<=k:
                    update1.append([i+p,dp0[i]+d])
                    price_list_add.add(i+p)
            # チケットあり
            if dp1[i]>=0:
                update0.append([i,dp1[i]+d])
        for ki,v in update0:
            dp0[ki]=maxb(dp0[ki],v)
        for ki,v in update1:
            dp1[ki]=maxb(dp1[ki],v)

        while price_list_add:
            price_list.add(price_list_add.pop())
    return maxb(max(dp0),max(dp1))

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