from heapq import heapify, heappop, heappush N, K = map(int, input().split()) A = list(map(int, input().split())) hp = [] heapify(hp) s = 0 ans = 0 for i in range(N - 1, -1, -1): if (N - 1 - i) < K -1: heappush(hp, A[i]) s += A[i] else: if i & 1: while len(hp) != K - 1: a = heappop(hp) s -= a ans = max(ans, s + A[i]) heappush(hp, A[i]) s += A[i] print(ans)