結果

問題 No.818 Dinner time
ユーザー mkawa2mkawa2
提出日時 2022-03-09 16:18:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 93,808 KB
最終ジャッジ日時 2023-10-11 17:10:13
合計ジャッジ時間 6,306 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,392 KB
testcase_01 AC 74 ms
71,524 KB
testcase_02 AC 74 ms
71,312 KB
testcase_03 AC 75 ms
71,232 KB
testcase_04 AC 73 ms
71,376 KB
testcase_05 AC 73 ms
71,288 KB
testcase_06 AC 73 ms
71,384 KB
testcase_07 AC 75 ms
71,280 KB
testcase_08 AC 75 ms
71,380 KB
testcase_09 AC 75 ms
71,332 KB
testcase_10 AC 75 ms
71,432 KB
testcase_11 AC 75 ms
71,112 KB
testcase_12 AC 76 ms
71,440 KB
testcase_13 AC 78 ms
71,328 KB
testcase_14 AC 77 ms
71,428 KB
testcase_15 AC 76 ms
71,456 KB
testcase_16 AC 76 ms
71,348 KB
testcase_17 AC 195 ms
92,536 KB
testcase_18 AC 134 ms
86,620 KB
testcase_19 AC 137 ms
86,820 KB
testcase_20 AC 152 ms
91,132 KB
testcase_21 AC 145 ms
89,220 KB
testcase_22 AC 136 ms
86,080 KB
testcase_23 AC 140 ms
86,924 KB
testcase_24 AC 160 ms
93,808 KB
testcase_25 AC 137 ms
86,892 KB
testcase_26 AC 133 ms
86,352 KB
testcase_27 AC 151 ms
90,364 KB
testcase_28 AC 142 ms
87,360 KB
testcase_29 AC 156 ms
90,976 KB
testcase_30 AC 149 ms
90,112 KB
testcase_31 AC 149 ms
90,076 KB
testcase_32 AC 139 ms
87,512 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, m = LI()
ab = LLI(n)
cs = [0]
for a, b in ab:
    cs.append(cs[-1]+max(a*m, a*(m-1)+b, b))

s = 0
mn = 0
ans = cs[-1]
for i in range(1, n)[::-1]:
    a, b = ab[i]
    s += max(a, b)
    mn = min(mn, s)
    cur = cs[i]+s-mn
    if cur > ans: ans = cur

print(ans)
0