import sys, math sys.setrecursionlimit(1000000) INF = 1 << 100 #mod = 1000000007 mod = 998244353 input = lambda: sys.stdin.readline().rstrip() li = lambda: list(map(int, input().split())) from heapq import * N, K = li() A = li() if K == 1: print(max(A[1:])) exit() hq = [] su = 0 acc = [-INF] * N for i in range(N)[::-1]: a = A[i] if len(hq) == K-1: x = heappop(hq) if x > a: heappush(hq, x) else: heappush(hq, a) su += a - x else: su += a heappush(hq, a) if len(hq) == K-1: acc[i] = su ans = -INF for i in range(1, N-1, 2): ans = max(ans, A[i] + acc[i+1]) print(ans)