#include using namespace std; using ll = long long; ll dp[2][310][310][310]; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n,k; cin>>n>>k; vector a(n); for(int i = 0;i>a[i]; vector ans(n,-1e18); for(int i = 0;i<2;i++) for(int j = 0;j=0;i--){ for(int j = 0;j=0){ dp[0][j][l][i-2] = max(dp[0][j][l][i-2],dp[0][j][l][i]); dp[1][j][l][i-2] = max(dp[1][j][l][i-2],dp[1][j][l][i]); } if(i%2==1){ ans[l] = max(ans[l],dp[0][j][l][i]); ans[j] = max(ans[j],dp[1][j][l][i]); } } if(i==0){ if(l+1=0) ans[j-1] = max(ans[j-1],dp[1][j][l][i]); } if(l+1=0){ dp[1][j-1][l][i-1] = max(dp[1][j-1][l][i-1],dp[1][j][l][i]+i*a[j-1]); } int need = l - j; if(i-need>=0){ dp[0][j][l][i-need] = max(dp[0][j][l][i-need],dp[1][j][l][i]); dp[1][j][l][i-need] = max(dp[1][j][l][i-need],dp[0][j][l][i]); } int res = i + 1; if(j+res=0&&l-res>=j-1) ans[l-res] = max(ans[l-res],dp[0][j][l][i]); } } } for(int i = 0;i