結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-04 11:09:06
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,432 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 149,364 KB
最終ジャッジ日時 2023-08-16 12:47:27
合計ジャッジ時間 42,402 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,592 KB
testcase_01 AC 71 ms
71,148 KB
testcase_02 AC 82 ms
75,848 KB
testcase_03 AC 71 ms
71,168 KB
testcase_04 AC 71 ms
71,412 KB
testcase_05 AC 71 ms
71,432 KB
testcase_06 AC 79 ms
75,804 KB
testcase_07 AC 74 ms
71,356 KB
testcase_08 AC 74 ms
71,348 KB
testcase_09 AC 137 ms
77,756 KB
testcase_10 AC 124 ms
77,052 KB
testcase_11 AC 125 ms
77,248 KB
testcase_12 AC 507 ms
94,512 KB
testcase_13 AC 1,510 ms
120,364 KB
testcase_14 AC 344 ms
85,240 KB
testcase_15 AC 206 ms
79,328 KB
testcase_16 AC 261 ms
79,528 KB
testcase_17 AC 289 ms
80,080 KB
testcase_18 AC 72 ms
71,312 KB
testcase_19 AC 71 ms
71,596 KB
testcase_20 AC 71 ms
71,284 KB
testcase_21 AC 116 ms
77,032 KB
testcase_22 AC 119 ms
77,096 KB
testcase_23 AC 116 ms
77,124 KB
testcase_24 AC 1,942 ms
145,644 KB
testcase_25 TLE -
testcase_26 AC 1,678 ms
118,592 KB
testcase_27 AC 1,739 ms
117,644 KB
testcase_28 AC 747 ms
96,032 KB
testcase_29 AC 746 ms
95,820 KB
testcase_30 AC 72 ms
71,152 KB
testcase_31 AC 71 ms
71,196 KB
testcase_32 AC 113 ms
77,016 KB
testcase_33 AC 119 ms
77,476 KB
testcase_34 AC 116 ms
77,432 KB
testcase_35 AC 1,881 ms
133,796 KB
testcase_36 AC 1,904 ms
140,748 KB
testcase_37 TLE -
testcase_38 AC 1,996 ms
146,792 KB
testcase_39 TLE -
testcase_40 AC 1,794 ms
132,628 KB
testcase_41 AC 1,742 ms
132,984 KB
testcase_42 AC 1,614 ms
118,000 KB
testcase_43 AC 1,644 ms
117,804 KB
testcase_44 AC 1,575 ms
117,624 KB
testcase_45 AC 1,615 ms
117,160 KB
testcase_46 AC 767 ms
107,252 KB
testcase_47 AC 759 ms
97,604 KB
testcase_48 AC 746 ms
96,104 KB
testcase_49 AC 734 ms
97,952 KB
testcase_50 AC 885 ms
104,540 KB
testcase_51 AC 765 ms
103,324 KB
testcase_52 AC 594 ms
97,168 KB
testcase_53 AC 597 ms
101,832 KB
testcase_54 AC 147 ms
80,756 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)
    dp0=[-1]*(k+1)
    dp1=[-1]*(k+1)
    dp0[0]=0
    price_list=set([0])
    for _,(p,d) in enumerate(pd):
        ndp0=[-1]*(k+1)
        ndp1=[-1]*(k+1)
        price_list_add=set()
        for i in price_list:
            # チケットなし
            if dp0[i]>=0:
                if i+p<=k:
                    ndp1[i+p]=max(ndp1[i+p],dp0[i]+d)
                    price_list_add.add(i+p)
                ndp0[i]=max(ndp0[i],dp0[i])
            # チケットあり
            if dp1[i]>=0:
                ndp0[i]=max(ndp0[i],dp1[i]+d)
                ndp1[i]=max(ndp1[i],dp1[i])

        dp0=ndp0
        dp1=ndp1
        for x in price_list_add:
            price_list.add(x)
    return max(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