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