結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,164 KB
testcase_01 AC 71 ms
71,308 KB
testcase_02 AC 82 ms
75,872 KB
testcase_03 AC 79 ms
71,280 KB
testcase_04 AC 71 ms
70,996 KB
testcase_05 AC 74 ms
71,432 KB
testcase_06 AC 79 ms
76,220 KB
testcase_07 AC 76 ms
71,144 KB
testcase_08 AC 75 ms
71,340 KB
testcase_09 AC 135 ms
77,272 KB
testcase_10 AC 114 ms
77,076 KB
testcase_11 AC 115 ms
77,380 KB
testcase_12 AC 529 ms
87,184 KB
testcase_13 AC 1,560 ms
104,300 KB
testcase_14 AC 368 ms
81,616 KB
testcase_15 AC 191 ms
78,904 KB
testcase_16 AC 247 ms
79,264 KB
testcase_17 AC 296 ms
79,040 KB
testcase_18 AC 73 ms
71,272 KB
testcase_19 AC 72 ms
71,452 KB
testcase_20 AC 73 ms
71,164 KB
testcase_21 AC 115 ms
77,088 KB
testcase_22 AC 111 ms
77,132 KB
testcase_23 AC 112 ms
77,152 KB
testcase_24 AC 1,962 ms
119,196 KB
testcase_25 TLE -
testcase_26 AC 1,656 ms
102,180 KB
testcase_27 AC 1,842 ms
101,096 KB
testcase_28 AC 751 ms
87,940 KB
testcase_29 AC 779 ms
88,528 KB
testcase_30 AC 75 ms
71,356 KB
testcase_31 AC 73 ms
71,116 KB
testcase_32 AC 106 ms
76,944 KB
testcase_33 AC 118 ms
76,936 KB
testcase_34 AC 114 ms
77,276 KB
testcase_35 AC 1,750 ms
113,244 KB
testcase_36 AC 1,945 ms
115,968 KB
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 AC 1,680 ms
100,872 KB
testcase_41 AC 1,803 ms
101,296 KB
testcase_42 AC 1,839 ms
100,900 KB
testcase_43 AC 1,613 ms
101,156 KB
testcase_44 AC 1,905 ms
101,588 KB
testcase_45 AC 1,864 ms
101,188 KB
testcase_46 AC 770 ms
91,536 KB
testcase_47 AC 763 ms
89,040 KB
testcase_48 AC 756 ms
89,676 KB
testcase_49 AC 862 ms
89,532 KB
testcase_50 AC 919 ms
91,524 KB
testcase_51 AC 811 ms
88,340 KB
testcase_52 AC 730 ms
84,532 KB
testcase_53 AC 693 ms
86,556 KB
testcase_54 AC 175 ms
81,032 KB
権限があれば一括ダウンロードができます

ソースコード

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:
        #ndp0=[-1]*(k+1)
        #ndp1=[-1]*(k+1)
        ndp0=dp0[:]
        ndp1=dp1[:]
        for i in price_list:
            # チケットなし
            if dp0[i]>=0:
                if i+p<=k:
                    ndp1[i+p]=maxb(ndp1[i+p],dp0[i]+d)
                    price_list_add.add(i+p)
                #ndp0[i]=maxb(ndp0[i],dp0[i])
            # チケットあり
            if dp1[i]>=0:
                ndp0[i]=maxb(ndp0[i],dp1[i]+d)
                #ndp1[i]=maxb(ndp1[i],dp1[i])
        dp0=ndp0
        dp1=ndp1
        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