#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } ll dp[310][310][310][2]; /* dp[i][l][r][t]: i回移動した,[l,r)決定済み, t = 0 => 今,左端にいます t = 1 => 右端 (r-1)にいます */ signed main(){ rep(i,310)rep(j,310)rep(k,310)rep(t,2)dp[i][j][k][t]=-LINF; rep(i,310) dp[0][i][i][0]=0,dp[0][i][i][1]=0; int n,k;cin>>n>>k; vector a(n); cin>>a; if(k==1){ rep(i,n){ ll res=-LINF; if(i) chmax(res,a[i-1]); if(i1) chmax(dp[i+2][l][r][t],dp[i][l][r][t]); // left to right if(t==0 and i+w-1<=k+1 and w>0) chmax(dp[i+w-1][l][r][1],dp[i][l][r][t]); // right to left if(t==1 and i+w-1<=k+1 and w>0) chmax(dp[i+w-1][l][r][0],dp[i][l][r][t]); // left -> left-1 if(t==0 and l>0) chmax(dp[i+1][l-1][r][t],dp[i][l][r][t]+a[l-1]*mul); // right -> right+1 if(t==1 and r res(n,-LINF); rep(i,k+2)rep(l,n+1)for(int r=l;r<=n;r++){ // 左端にいます int rem=k+1-i; if(l+rem