from heapq import heappop,heappush n,k = map(int,input().split()) A = list(map(int,input().split())) ans = 0 score = 0 size = 0 h = [] for i in range(n)[::-1]: a = A[i] if i%2 == 0: size += 1 heappush(h,a) score += a continue # print(i,a,h,score) while size > k: x = heappop(h) size -= 1 score -= x if size == k: ans = max(ans,score+a-h[0]) else: ans = max(ans,score+a) heappush(h,a) score += a size += 1 print(ans)