import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**9 md = 998244353 # md = 10**9+7 n, k = LI() aa = LI() dp = [{} for _ in range(k+1)] for i, a in enumerate(aa): dp[k][0, i, i] = a*k def chmax(i, j, l, r, val): now = dp[i].setdefault((j, l, r), -inf) if val > now: dp[i][j, l, r] = val ans = [-inf]*n for i in range(k, -1, -1): for (j, l, r), pre in dp[i].items(): p0 = r-i if j else l+i if l <= p0 <= r: ans[p0] = max(ans[p0], pre) if i == 0: continue # 左に出る d = r-l+1 if j else 1 if l-1 >= 0 and i-d >= 0: chmax(i-d, 0, l-1, r, pre+(i-d)*aa[l-1]) # 右に出る d = 1 if j else r-l+1 if r+1 < n and i-d >= 0: chmax(i-d, 1, l, r+1, pre+(i-d)*aa[r+1]) # 動かない if l != r: chmax(i-2, j, l, r, pre) print(*ans, sep="\n")