#include using namespace std; #define range(i,a,b) for(int i=(a); i < (b); i++) #define rep(i,n) range(i,0,n) #define MIN -1000000 #define Un 3000 int n,m,dp[Un][Un+2][2],w[Un]; int solve(int s){ rep(i,n) rep(j,m+2) rep(k,2) dp[i][j][k] = MIN; dp[0][s][s] = 0; rep(i,n-1) range(j,max(s,i+m-s-n+1),min(i+s,m)+1) rep(k,2){ if (dp[i][j][k] == MIN) continue; dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][k]); dp[i+1][j+1][1] = max(dp[i+1][j+1][1],dp[i][j][k]+w[i]*k); } return max(dp[n-1][m][0],dp[n-1][m][1]+w[n-1]*s); } int main(){ int sum = 0; cin >> n >> m; rep(i,n){cin >> w[i]; sum += w[i];} if (n == 0) cout << 0 << endl; else if (n == m) cout << sum << endl; else cout << max(solve(0),solve(1)) << endl; return 0; }