結果

問題 No.561 東京と京都
ユーザー asumo0729asumo0729
提出日時 2020-12-16 14:15:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,860 KB
実行使用メモリ 53,572 KB
最終ジャッジ日時 2023-10-20 09:36:37
合計ジャッジ時間 1,865 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,572 KB
testcase_01 AC 36 ms
53,572 KB
testcase_02 AC 36 ms
53,572 KB
testcase_03 AC 36 ms
53,572 KB
testcase_04 AC 35 ms
53,572 KB
testcase_05 AC 36 ms
53,572 KB
testcase_06 AC 36 ms
53,572 KB
testcase_07 AC 37 ms
53,572 KB
testcase_08 AC 37 ms
53,572 KB
testcase_09 AC 37 ms
53,572 KB
testcase_10 AC 37 ms
53,572 KB
testcase_11 AC 37 ms
53,572 KB
testcase_12 AC 36 ms
53,572 KB
testcase_13 AC 38 ms
53,572 KB
testcase_14 AC 36 ms
53,572 KB
testcase_15 AC 38 ms
53,572 KB
testcase_16 AC 37 ms
53,572 KB
testcase_17 AC 38 ms
53,572 KB
testcase_18 AC 39 ms
53,572 KB
testcase_19 AC 38 ms
53,572 KB
testcase_20 AC 36 ms
53,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
stdin=sys.stdin

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
tp=lambda:tuple(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
yp=lambda:print('Yes')
np=lambda:print('No')

n,d=lp()
inf=float('inf')
dp=[[-inf for _ in range(2)]for _ in range(n)]
for i in range(n):
    now=lp()
    if i==0:
        dp[0][0]=now[0]
        dp[0][1]=now[1]-d
    else:
        dp[i][0]=max(dp[i-1][0]+now[0],dp[i-1][1]+now[0]-d)
        dp[i][1]=max(dp[i-1][1]+now[1],dp[i-1][0]+now[1]-d)

print(max(dp[-1][0],dp[-1][1]))
0