from heapq import heapify, heappop, heappush N, K = map(int, input().split()) A = [int(a) for a in input().split()] hq = [] heapify(hq) s = 0 for i in range(N - K + 1, N): heappush(hq, A[i]) s += A[i] ans = -1 << 60 for i in range(N - K, -1, -1): if i & 1: ans = max(ans, s + A[i]) s += A[i] heappush(hq, A[i]) m = heappop(hq) s -= m print(ans)