import sys input = sys.stdin.readline from heapq import * N,K=map(int,input().split()) A=list(map(int,input().split())) hp = [] sm = 0 ans = 0 for i in range(N-1,0,-1): while len(hp)>=K: d = heappop(hp) sm -= d heappush(hp,A[i]) sm += A[i] if i%2==1: ans = max(ans, sm) print(ans)