from heapq import heappop, heappush n, k = map(int, input().split()) a = list(map(int, input().split())) if k == 1: print(max(a[1::2])); exit() hq = [] s = 0 ans = 0 for i in range(n-1, -1, -1): if len(hq) < k-1: heappush(hq, a[i]) s += a[i] elif i%2 == 0: m = heappop(hq) heappush(hq, max(a[i], m)) s += max(a[i], m)-m else: ans = max(ans, a[i]+s) m = heappop(hq) heappush(hq, max(a[i], m)) s += max(a[i], m)-m print(ans)