import heapq N,K = map(int,input().split()) A = list(map(int,input().split())) heap = [] ans = 0 for i in range(N-1,N-K,-1): ans += A[i] heapq.heappush(heap,A[i]) cur = N-K if cur%2==0: ans += A[cur] heapq.heappush(heap,A[cur]) ans -= heapq.heappop(heap) cur -= 1 ans += A[cur] cnt = ans while cur>=3: heapq.heappush(heap,A[cur]) cnt -= heapq.heappop(heap) cur -= 1 cnt += A[cur] heapq.heappush(heap,A[cur]) cnt -= heapq.heappop(heap) cur -= 1 cnt += A[cur] ans = max(cnt,ans) print(ans)