from heapq import heappop,heappush n,k=map(int,input().split()) a=list(map(int,input().split())) mx=0 hq=[] sm=0 for i in range(n-1,-1,-1): if i%2==1 and len(hq)==k-1: mx=max(mx,sm+a[i]) sm+=a[i] heappush(hq,a[i]) if len(hq)>=k: sm-=heappop(hq) print(mx)