from collections import deque from itertools import accumulate inf = 10**18 def sliding_max(A, rng): d = deque() for i, a in enumerate(A): while d and d[0] <= i - rng: d.popleft() while d and A[d[-1]] < a: d.pop() d.append(i) yield A[d[0]] N, K, M = map(int, input().split()) A = list(map(int, input().split())) S = [0] + list(accumulate(A)) # dp[j,i]: i桁目までみた、j個かたまりできた-> max dp = [[-inf]*(N+1) for _ in range(K+1)] dp[0][0] = 0 for i in range(K): val = tuple(dp[i][j] - S[j] for j in range(N)) for j, x in enumerate(sliding_max(val, M), 1): dp[i+1][j] = max(dp[i+1][j], x + S[j]) val = tuple(dp[i][j] + S[j] for j in range(N)) for j, x in enumerate(sliding_max(val, M), 1): dp[i+1][j] = max(dp[i+1][j], x - S[j]) print(dp[K][N])