結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー mkawa2mkawa2
提出日時 2022-01-24 16:19:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 665 ms / 2,000 ms
コード長 1,157 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 86,600 KB
実行使用メモリ 78,412 KB
最終ジャッジ日時 2023-08-21 04:43:10
合計ジャッジ時間 19,031 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,288 KB
testcase_01 AC 72 ms
71,068 KB
testcase_02 AC 86 ms
75,524 KB
testcase_03 AC 77 ms
75,516 KB
testcase_04 AC 73 ms
71,004 KB
testcase_05 AC 72 ms
70,908 KB
testcase_06 AC 84 ms
75,672 KB
testcase_07 AC 72 ms
71,368 KB
testcase_08 AC 82 ms
75,676 KB
testcase_09 AC 110 ms
77,040 KB
testcase_10 AC 104 ms
76,448 KB
testcase_11 AC 106 ms
76,516 KB
testcase_12 AC 211 ms
77,728 KB
testcase_13 AC 462 ms
78,080 KB
testcase_14 AC 159 ms
77,396 KB
testcase_15 AC 145 ms
77,228 KB
testcase_16 AC 161 ms
78,012 KB
testcase_17 AC 183 ms
78,052 KB
testcase_18 AC 73 ms
71,272 KB
testcase_19 AC 72 ms
71,328 KB
testcase_20 AC 72 ms
71,104 KB
testcase_21 AC 98 ms
75,732 KB
testcase_22 AC 104 ms
76,544 KB
testcase_23 AC 104 ms
76,348 KB
testcase_24 AC 535 ms
78,208 KB
testcase_25 AC 552 ms
78,124 KB
testcase_26 AC 490 ms
77,768 KB
testcase_27 AC 556 ms
78,092 KB
testcase_28 AC 426 ms
78,192 KB
testcase_29 AC 385 ms
78,028 KB
testcase_30 AC 71 ms
71,344 KB
testcase_31 AC 72 ms
71,152 KB
testcase_32 AC 103 ms
76,656 KB
testcase_33 AC 104 ms
76,044 KB
testcase_34 AC 100 ms
75,748 KB
testcase_35 AC 447 ms
78,072 KB
testcase_36 AC 600 ms
77,736 KB
testcase_37 AC 469 ms
77,892 KB
testcase_38 AC 664 ms
78,068 KB
testcase_39 AC 665 ms
77,956 KB
testcase_40 AC 545 ms
78,296 KB
testcase_41 AC 462 ms
77,852 KB
testcase_42 AC 474 ms
77,932 KB
testcase_43 AC 458 ms
77,772 KB
testcase_44 AC 468 ms
78,076 KB
testcase_45 AC 465 ms
78,080 KB
testcase_46 AC 382 ms
78,084 KB
testcase_47 AC 408 ms
78,180 KB
testcase_48 AC 388 ms
78,068 KB
testcase_49 AC 393 ms
78,192 KB
testcase_50 AC 395 ms
78,412 KB
testcase_51 AC 434 ms
77,892 KB
testcase_52 AC 296 ms
78,092 KB
testcase_53 AC 321 ms
78,304 KB
testcase_54 AC 145 ms
76,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = (1 << 63)-1
inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

def main():
    n, k = LI()
    pd = LLI(n)
    pd.sort(key=lambda x: -x[0])

    def chmax(arr, i, val):
        if val < 0: return
        if val > arr[i]: arr[i] = val

    dp0 = [-inf]*(k+1)
    dp1 = [-inf]*(k+1)
    dp0[0] = 0
    for p, d in pd:
        for i in range(k, -1, -1):
            if i+p <= k: chmax(dp1, i+p, dp0[i]+d)
            chmax(dp0, i, dp1[i]+d)

    ans = max(max(dp0), max(dp1))
    print(ans)

main()
0