#include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; const ll INF = 1e18; ll dp[305][305][305][2]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, k; cin >> n >> k; vector a(n); for(int i = 0; i < n; i++) cin >> a[i]; for(int j = k; j >= 0; j--){ for(int l = 0; l < n; l++){ for(int r = l+1; r <= n; r++){ dp[l][r][j][0] = -INF; dp[l][r][j][1] = -INF; } } } for(int l = 0; l < n; l++){ dp[l][l+1][k][0] = a[l]*k; dp[l][l+1][k][1] = a[l]*k; } for(int j = k; j > 0; j--){ // cout << j << endl; for(int l = 0; l < n; l++){ for(int r = l+1; r <= n; r++){ for(int p = 0; p < 2; p++){ // cout << "dp[" << l << "][" << r << "][" << j << "][" << p << "] = " << dp[l][r][j][p] << endl; int cur = (p == 0 ? l : r-1); // とどまる if(j >= 2 && r-l >= 2) chmax(dp[l][r][j-2][p], dp[l][r][j][p]); // l-1に行く int dist = cur-(l-1); if(l > 0 && dist <= j) chmax(dp[l-1][r][j-dist][0], dp[l][r][j][p]+a[l-1]*(j-dist)); // rに行く dist = r-cur; if(r < n && dist <= j) chmax(dp[l][r+1][j-dist][1], dp[l][r][j][p]+a[r]*(j-dist)); } } } } for(int i = 0; i < n; i++){ ll ans = -INF; for(int l = 0; l <= i; l++){ for(int r = max(i+1, l+1); r <= n; r++){ if(r-l < 2) continue; // lから来る chmax(ans, dp[l][r][i-l][0]); // r-1から来る chmax(ans, dp[l][r][(r-1)-i][1]); } } cout << ans << endl; } }