from heapq import heappushpop, heappush from itertools import accumulate n, k = map(int, input().split()) ans = -10 ** 20 h = [] now = 0 for x in accumulate(map(int, input().split())): if len(h) == k - 1: ans = max(ans, k * x - now) now += x + heappushpop(h, -x) else: now += x heappush(h, -x) print(ans)