from heapq import heapify, heappop, heappush n, k = map(int, input().split()) A = list(map(int, input().split())) ans = 0 res = 0 H = [] heapify(H) for i in range(n - 1, -1, -1): if i % 2 == 1 and len(H) == k - 1: ans = max(ans, res + A[i]) heappush(H, A[i]) res += A[i] if len(H) == k: res -= heappop(H) print(ans)