#include using namespace std; using Int = long long; const char newl = '\n'; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void drop(const T &x){cout< vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } template struct SegmentTree{ // using H = function; Int n,height; H h; E ei; vector laz; SegmentTree(H h,E ei):h(h),ei(ei){} void init(Int n_){ n=1;height=0; while(n>i); } void update(Int a,Int b,E x){ if(a>=b) return; thrust(a+=n); thrust(b+=n-1); for(Int l=a,r=b+1;l>=1,r>>=1){ if(l&1) laz[l]=h(laz[l],x),l++; if(r&1) --r,laz[r]=h(laz[r],x); } } E get_val(Int a){ thrust(a+=n); return laz[a]; } void set_val(Int a,E x){ thrust(a+=n); laz[a]=x; } }; //INSERT ABOVE HERE const Int MAX = 303; const Int INF = 1e18; Int dp[MAX][2][MAX][MAX]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int n,k; cin>>n>>k; auto as=read(n); vector ans(n); // start from parity for(Int p=0;p<2;p++){ // init for(Int i=0;i<=k;i++) for(Int l=0;l seg(h,-INF); seg.init(n); for(Int i=k-1;i>=0;i--){ for(Int l=0;l=1) chmax(dp[i-1][0][l-1][r],res+as[l-1]*(i-1)); if(i>=2) chmax(dp[i-2][0][l][r],res); if((r-l)<=i) chmax(dp[i-(r-l)][1][l][r],res); } if(dp[i][1][l][r]!=-INF){ Int res=dp[i][1][l][r]; if(r+1=2) chmax(dp[i-2][1][l][r],res); if((r-l)<=i) chmax(dp[i-(r-l)][0][l][r],res); } } } } for(Int i=p;i