#include #define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i)) #define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i)) #define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i)) #define ALL(x) ::std::begin(x), ::std::end(x) using namespace std; vector solve(int n, int64_t k, const vector& a) { vector > > > dp(k + 1, vector > >(n + 1, vector >(n + 1, {INT64_MIN, INT64_MIN}))); REP (l, n) { REP (p, 2) { dp[k][l][l + 1][p] = a[l] * k; } } REP_R (j, k) { REP (l, n) { REP3 (r, l + 1, n + 1) { REP (p, 2) { if (j + 2 < k and dp[j + 2][l][r][p] != INT64_MIN and r - l >= 2) { dp[j][l][r][p] = max(dp[j][l][r][p], dp[j + 2][l][r][p]); } if (dp[j + 1][l + 1][r][false] != INT64_MIN and not p) { dp[j][l][r][p] = max(dp[j][l][r][p], dp[j + 1][l + 1][r][false] + a[l] * j); } if (dp[j + 1][l][r - 1][true] != INT64_MIN and p) { dp[j][l][r][p] = max(dp[j][l][r][p], dp[j + 1][l][r - 1][true] + a[r - 1] * j); } if (j + r - 1 - l < k and dp[j + r - 1 - l][l + 1][r][true] != INT64_MIN and not p) { dp[j][l][r][p] = max(dp[j][l][r][p], dp[j + r - 1 - l][l + 1][r][true] + a[l] * j); } if (j + r - 1 - l < k and dp[j + r - 1 - l][l][r - 1][false] != INT64_MIN and p) { dp[j][l][r][p] = max(dp[j][l][r][p], dp[j + r - 1 - l][l][r - 1][false] + a[r - 1] * j); } } } } } vector ans(n, INT64_MIN); REP (i, n) { REP (l, i + 1) { REP3 (r, i + 1, n + 1) { if (i - l < k) { ans[i] = max(ans[i], dp[i - l][l][r][false]); } if (r - 1 - i < k) { ans[i] = max(ans[i], dp[r - 1 - i][l][r][true]); } } } } return ans; } // generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator) int main() { int64_t N; int64_t K; cin >> N; cin >> K; vector A(N); REP (i, N) { cin >> A[i]; } auto ans = solve(N, K, A); REP (i, N) { cout << ans[i] << endl; } return 0; }