import collections class MaxQueue(collections.deque): def enqueue(self, val): count = 1 while self and self[-1][0] < val: count += self.pop()[1] self.append([val, count]) def dequeue(self): ans = self.max() self[0][1] -= 1 if self[0][1] <= 0: self.popleft() return ans def max(self): return self[0][0] if self else 0 readlist = lambda: list(map(int, input().split())) N, K = readlist() A = readlist() P = [0] for x in A: P.append(P[-1] + x) for x in A: P.append(P[-1]) dp = [0] * (N + K + 1) maxq = MaxQueue() length = 0 for i in range(N - 1, -1, -1): maxq.enqueue(dp[i+2] + P[i+1]) if i <= N-K: maxq.dequeue() dp[i] = max(dp[i+1], maxq.max() - P[i]) print(dp[0])