local mmi, mma = math.min, math.max local n, m = io.read("*n", "*n") local w = {} for i = 1, n do w[i] = io.read("*n") end if m == 0 then print(0) os.exit() end local inf = 1000000007 local dp1a, dp1b = {}, {} local dp2a, dp2b = {}, {} dp1a[1] = 0 dp1b[1] = -inf for i = 2, n do local srca = i % 2 == 0 and dp1a or dp2a local srcb = i % 2 == 0 and dp1b or dp2b local dsta = i % 2 == 0 and dp2a or dp1a local dstb = i % 2 == 0 and dp2b or dp1b dsta[1] = -inf for j = 2, i do dsta[j] = mma(srca[j - 1] + w[i - 1], srcb[j - 1]) if i == n then dsta[j] = dsta[j] + w[n] end end for j = 1, i - 1 do dstb[j] = mma(srca[j], srcb[j]) end dstb[i] = -inf end local tbla = n % 2 == 0 and dp2a or dp1a local tblb = n % 2 == 0 and dp2b or dp1b local ret = mma(tbla[m], tblb[m]) dp1a[1] = -inf dp1b[1] = -inf for i = 2, n do local srca = i % 2 == 0 and dp1a or dp2a local srcb = i % 2 == 0 and dp1b or dp2b local dsta = i % 2 == 0 and dp2a or dp1a local dstb = i % 2 == 0 and dp2b or dp1b dsta[1] = 0 for j = 2, i - 1 do dsta[j] = mma(srca[j - 1] + w[i - 1], srcb[j - 1]) end dsta[i] = -inf for j = 1, i - 1 do dstb[j] = mma(srca[j], srcb[j]) end dstb[i] = -inf end tbla = n % 2 == 0 and dp2a or dp1a tblb = n % 2 == 0 and dp2b or dp1b ret = mma(ret, tbla[m], tblb[m]) print(ret)