import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(int[]), n = rd[0], m = rd[1]; auto w = readln.split.to!(int[]); auto calc1() { auto dp = new int[][][](n+1, m+1, 2); foreach (i; 0..n+1) foreach (j; 0..m+1) foreach (k; 0..2) dp[i][j][k] = -10^^9; dp[1][0][0] = 0; foreach (i; 1..n) foreach (j; 0..m+1) { dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][0], dp[i][j][1]); if (j < m) dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j][0], dp[i][j][1] + w[i-1]); } return max(dp[n][m][0], dp[n][m][1]); } auto calc2() { auto dp = new int[][][](n+1, m+1, 2); foreach (i; 0..n+1) foreach (j; 0..m+1) foreach (k; 0..2) dp[i][j][k] = -10^^9; dp[1][1][1] = 0; foreach (i; 1..n) foreach (j; 0..m+1) { dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][0], dp[i][j][1]); if (j < m) dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j][0], dp[i][j][1] + w[i-1]); } return max(dp[n][m][0], dp[n][m][1] + w[n-1]); } writeln(max(calc1, calc2)); }