import heapq class Heap(): def __init__(self, maxi = False): self.sum = 0 self.al = [] self.maxi = maxi self.len = 0 def __len__(self): return len(self.al) def add(self, x): if self.maxi: heapq.heappush(self.al, -x) else: heapq.heappush(self.al, x) self.sum += x def pop(self): if self.maxi: now = heapq.heappop(self.al) self.sum += now return -now else: now = heapq.heappop(self.al) self.sum -= now return now def top(self): now = self.pop() self.add(now) return now def solve(n, k, a): Q = Heap() ans = 0 for i in range(n - 1, -1, -1): if i % 2 == 1 and len(Q) == k - 1: ans = max(ans, a[i] + Q.sum) Q.add(a[i]) if len(Q) >= k: Q.pop() return ans n, k = map(int,input().split()) a = list(map(int,input().split())) print(solve(n, k , a))