#include using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; constexpr int MAX = 3100; int dp[MAX][2]; int sum[MAX]; static int qf[MAX], q2f[MAX]; static int qs[MAX], q2s[MAX]; signed main(){ int N, K, M, A; cin>>N>>K>>M; sum[0] = 0; for(int i = 0; i < N; i++){ cin>>A; sum[i+1] = sum[i] + A; if(i < M) dp[i][1] = abs(sum[i+1]); } for(int j = 2, k = 0; j <= K; j++, k = !k){ int f = 0, e = 0, f2 = 0, e2 = 0; int L = min(N, M * j); for(int i = j-1; i < L; i++){ int num = dp[i-1][!k] - sum[i]; int num2 = dp[i-1][!k] + sum[i]; while(e - f && qs[e-1] < num) e--; qf[e] = i; qs[e] = num; e++; while(e - f && qf[f] < i - M + 1) f++; while(e2 - f2 && q2s[e2-1] < num2) e2--; q2f[e2] = i; q2s[e2] = num2; e2++; while(e2 - f2 && q2f[f2] < i - M + 1) f2++; dp[i][k] = max(qs[f] + sum[i+1], q2s[f2] - sum[i+1]); } } cout<