#include using namespace std; int w[3010]; int n,m; int dp[3010][3010][2][2]; int dfs(int x,int y,int u,int f){ if( y < 0 ) return -1e9; if( x == n ){ if( y != 0 ) return -1e9; return f == 1 && u == 1 ? w[n-1] : 0; } if( dp[x][y][u][f] != -1 ) return dp[x][y][u][f]; int ans = -1e9; ans = max(dfs(x+1,y,0,f),dfs(x+1,y-1,1,f)+(u*w[x-1])); return dp[x][y][u][f] = ans; } int main(){ cin >> n >> m; for(int i = 0 ; i < n ; i++) cin >> w[i]; memset(dp,-1,sizeof(dp)); cout << max(dfs(1,m,0,0),dfs(1,m-1,1,1)) << endl; }