#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using vll = vector; using vi = vector; using vvi = vector>; using vvll = vector>; const int inf = 1e9; const ll md = 1000000007; int dp[3005][3005][2]; int w[3005]; int main() { int n,m; cin>>n>>m; rep(i,n) cin>>w[i]; rep(i,n+1) rep(j,n+1) rep(k,2) dp[i][j][k]=-inf; dp[0][0][1]=0; rep(i,n) rep(j,min(i+1,m+1)) rep(k,1){ int pre=dp[i][j][k]; if (pre==-inf) continue; dp[i+1][j][0]=max(dp[i+1][j][0],pre); if (k) dp[i+1][j+1][1]=max(dp[i+1][j+1][1],pre+w[i]); else dp[i+1][j+1][1]=max(dp[i+1][j+1][1],pre); } int ans=dp[n][m][1]; rep(i,n+1) rep(j,n+1) rep(k,2) dp[i][j][k]=-inf; dp[0][0][0]=0; rep(i,n) rep(j,min(i+1,m+1)) rep(k,1){ int pre=dp[i][j][k]; if (pre==-inf) continue; dp[i+1][j][0]=max(dp[i+1][j][0],pre); if (k) dp[i+1][j+1][1]=max(dp[i+1][j+1][1],pre+w[i]); else dp[i+1][j+1][1]=max(dp[i+1][j+1][1],pre); } ans=max(ans,dp[n][m][0]); cout<