from heapq import * n, K = map(int, input().split()) A = list(map(int, input().split())) tot = 0 l_tot = 0 hq = [] ans = 0 for i, a in enumerate(A[:K], 1): ans += i * a for a in A: tot += a if len(hq) >= K - 1: score = tot * K - l_tot ans = max(ans, score) l_tot += tot heappush(hq, -tot) if len(hq) == K: l_tot += heappop(hq) print(ans)