結果

問題 No.2139 K Consecutive Sushi
ユーザー H3PO4H3PO4
提出日時 2022-12-20 21:37:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,493 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 113,792 KB
最終ジャッジ日時 2024-04-29 02:59:13
合計ジャッジ時間 6,913 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
51,840 KB
testcase_01 AC 47 ms
52,352 KB
testcase_02 AC 42 ms
52,352 KB
testcase_03 AC 271 ms
113,152 KB
testcase_04 AC 273 ms
112,896 KB
testcase_05 AC 272 ms
113,152 KB
testcase_06 AC 267 ms
112,896 KB
testcase_07 AC 273 ms
113,280 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 275 ms
113,408 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 42 ms
52,096 KB
testcase_14 AC 43 ms
52,480 KB
testcase_15 AC 43 ms
52,608 KB
testcase_16 AC 43 ms
52,096 KB
testcase_17 AC 41 ms
52,224 KB
testcase_18 AC 96 ms
76,544 KB
testcase_19 AC 98 ms
76,160 KB
testcase_20 AC 94 ms
75,648 KB
testcase_21 WA -
testcase_22 AC 109 ms
75,904 KB
testcase_23 AC 138 ms
78,592 KB
testcase_24 AC 166 ms
85,376 KB
testcase_25 AC 226 ms
102,656 KB
testcase_26 AC 136 ms
78,592 KB
testcase_27 AC 157 ms
84,608 KB
testcase_28 AC 166 ms
84,992 KB
testcase_29 AC 148 ms
79,360 KB
testcase_30 AC 171 ms
87,936 KB
testcase_31 AC 259 ms
109,568 KB
testcase_32 AC 139 ms
79,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline


class SegmentTree:
    """
    https://qiita.com/dn6049949/items/afa12d5d079f518de368 から拝借しています。
    """

    def __init__(self, size, f=lambda x, y: min(x, y), default=10 ** 9 + 7):
        self.size = 2 ** (size - 1).bit_length()
        self.default = default
        self.dat = [default] * (self.size * 2)
        self.f = f

    def initialize(self, A):
        for i, a in enumerate(A, self.size):
            self.dat[i] = a
        for i in range(self.size - 1, 0, -1):
            self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1])

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1])

    def query(self, l, r):
        """半開区間[l,r)"""
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1
            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res


N, K = map(int, input().split())
A = tuple(map(int, input().split()))
dp = SegmentTree(N + 1)
dp.update(0, 0)
for i, a in enumerate(A, 1):
    dp.update(i, dp.query(max(0, i - K), i) + a)
print(sum(A) - dp.query(N + 1 - K, N + 1))
0