import sys
sys.setrecursionlimit(100000)
N, K = map(int, input().split())
p = list(map(int, input().split()))
pre = [0] * (N + 1)
wpre = [0] * (N + 1)
for i in range(1, N + 1):
pre[i] = pre[i - 1] + p[i - 1]
wpre[i] = wpre[i - 1] + p[i - 1] *(i - 1)
ans = 0
def calc(s, t, dep):
global ans
if t - s + 1 < 3 or dep > K:
return
W = pre[t + 1] - pre[s]
Wi = wpre[t + 1] - wpre[s]
best, val = -1, float('inf')
for m in range(s + 1, t):
d = abs(Wi - m * W)
if d < val or (d == val and m < best):
best, val = m, d
ans += p[best]
calc(s, best - 1, dep + 1)
calc(best + 1, t, dep + 1)
calc(0, N - 1, 1)
print(ans)