結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,280 KB
testcase_01 AC 72 ms
71,280 KB
testcase_02 AC 90 ms
75,900 KB
testcase_03 AC 74 ms
75,772 KB
testcase_04 AC 73 ms
71,256 KB
testcase_05 AC 71 ms
71,592 KB
testcase_06 AC 79 ms
75,660 KB
testcase_07 AC 71 ms
71,372 KB
testcase_08 AC 79 ms
76,164 KB
testcase_09 AC 151 ms
76,468 KB
testcase_10 AC 97 ms
76,308 KB
testcase_11 AC 96 ms
76,372 KB
testcase_12 AC 190 ms
77,636 KB
testcase_13 AC 315 ms
78,416 KB
testcase_14 AC 145 ms
77,632 KB
testcase_15 AC 133 ms
77,392 KB
testcase_16 AC 148 ms
77,996 KB
testcase_17 AC 169 ms
78,160 KB
testcase_18 AC 72 ms
71,520 KB
testcase_19 AC 73 ms
71,284 KB
testcase_20 AC 72 ms
71,440 KB
testcase_21 AC 96 ms
76,408 KB
testcase_22 AC 99 ms
75,952 KB
testcase_23 AC 99 ms
76,352 KB
testcase_24 AC 437 ms
78,568 KB
testcase_25 AC 436 ms
78,560 KB
testcase_26 AC 402 ms
78,008 KB
testcase_27 AC 450 ms
78,024 KB
testcase_28 AC 339 ms
78,440 KB
testcase_29 AC 365 ms
78,556 KB
testcase_30 AC 72 ms
71,544 KB
testcase_31 AC 74 ms
71,056 KB
testcase_32 AC 96 ms
76,200 KB
testcase_33 AC 101 ms
76,328 KB
testcase_34 AC 98 ms
76,192 KB
testcase_35 AC 435 ms
78,440 KB
testcase_36 AC 442 ms
78,528 KB
testcase_37 AC 318 ms
78,332 KB
testcase_38 AC 403 ms
78,300 KB
testcase_39 AC 447 ms
78,212 KB
testcase_40 AC 367 ms
78,444 KB
testcase_41 AC 329 ms
78,296 KB
testcase_42 AC 341 ms
78,284 KB
testcase_43 AC 410 ms
78,200 KB
testcase_44 AC 337 ms
78,288 KB
testcase_45 AC 415 ms
78,260 KB
testcase_46 AC 327 ms
78,216 KB
testcase_47 AC 344 ms
78,520 KB
testcase_48 AC 339 ms
78,436 KB
testcase_49 AC 343 ms
78,092 KB
testcase_50 AC 363 ms
78,496 KB
testcase_51 AC 376 ms
78,488 KB
testcase_52 AC 245 ms
78,076 KB
testcase_53 AC 266 ms
78,392 KB
testcase_54 AC 179 ms
77,036 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

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

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

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