結果

問題 No.2139 K Consecutive Sushi
ユーザー mkawa2mkawa2
提出日時 2022-12-04 00:06:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,147 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 82,232 KB
実行使用メモリ 117,204 KB
最終ジャッジ日時 2024-04-19 10:27:38
合計ジャッジ時間 3,900 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
55,504 KB
testcase_01 AC 35 ms
54,752 KB
testcase_02 AC 36 ms
54,292 KB
testcase_03 AC 125 ms
116,568 KB
testcase_04 AC 118 ms
116,572 KB
testcase_05 AC 117 ms
116,452 KB
testcase_06 AC 116 ms
116,448 KB
testcase_07 AC 122 ms
116,552 KB
testcase_08 AC 132 ms
117,196 KB
testcase_09 AC 128 ms
116,584 KB
testcase_10 AC 138 ms
117,204 KB
testcase_11 AC 129 ms
116,580 KB
testcase_12 AC 131 ms
116,696 KB
testcase_13 AC 36 ms
55,300 KB
testcase_14 AC 35 ms
54,632 KB
testcase_15 AC 35 ms
54,436 KB
testcase_16 AC 35 ms
54,072 KB
testcase_17 AC 34 ms
55,464 KB
testcase_18 AC 44 ms
65,632 KB
testcase_19 AC 42 ms
64,420 KB
testcase_20 AC 46 ms
65,596 KB
testcase_21 AC 35 ms
55,904 KB
testcase_22 AC 47 ms
66,108 KB
testcase_23 AC 54 ms
74,580 KB
testcase_24 AC 70 ms
88,492 KB
testcase_25 AC 97 ms
106,808 KB
testcase_26 AC 53 ms
75,228 KB
testcase_27 AC 67 ms
86,688 KB
testcase_28 AC 67 ms
86,700 KB
testcase_29 AC 57 ms
77,536 KB
testcase_30 AC 73 ms
90,588 KB
testcase_31 AC 111 ms
111,596 KB
testcase_32 AC 57 ms
78,920 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

from collections import deque

n, k = LI()
aa = LI()
cs = [0]
for a in aa: cs.append(cs[-1]+a)

dp = [0]+[-inf]*n
mx = deque()
mx.append((0, 0))
mx.append((1, -cs[1]))
for i, a in enumerate(aa):
    while mx[0][0] < i+1-(k-1): mx.popleft()
    dp[i+1] = max(dp[i], cs[i+1]+mx[0][1])
    if i == n-1: break
    v = dp[i+1]-cs[i+2]
    while mx and mx[-1][-1] <= v: mx.pop()
    mx.append((i+2, v))

# pDB(dp)
print(dp[-1])
0