import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdlib, std.datetime; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto K = s[1]; auto M = s[2]; auto A = readln.split.map!(to!long).array; auto S = new long[][](N, N); foreach (i; 0..N) { long tmp = 0; foreach (j; i..N) { tmp += A[j]; S[i][j] = abs(tmp); } } long calc(bool init_pos) { auto dp = new long[][](N+1, K+1); foreach (i; 0..N+1) dp[i][] = -(1L << 59); dp[0][0] = 0; foreach (i; 0..N) { bool positive = init_pos; foreach (j; 0..K) { if (positive) { dp[i+1][j] = max(dp[i+1][j], dp[i][j] + A[i]); dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i]); } else { dp[i+1][j] = max(dp[i+1][j], dp[i][j] - A[i]); dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] - A[i]); } positive = !positive; } } long ans = 0; foreach (j; 0..K+1) ans = max(ans, dp[N][j]); return ans; } writeln(max(calc(true), calc(false))); }