#include #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector VI; typedef pair P; typedef tuple t3; typedef tuple t4; typedef tuple t5; #define rep(a,n) for(ll a = 0;a < n;a++) #define repi(a,b,n) for(ll a = b;a < n;a++) using namespace std; static const ll INF = 1e15; const ll mod = 1000000007; template static inline void chmin(T & ref, const T value) { if (ref > value) ref = value; } template static inline void chmax(T& ref, const T value) { if (ref < value) ref = value; } int main() { //dp[i][j]...i-1番目までで、j個に分割している個数 ll n, m, k; cin >> n >> k >> m; vector as(n); vector sums(n+1, 0); rep(i, n) { cin >> as[i]; sums[i + 1] = sums[i] + as[i]; } vector> dp(n + 1, vector(n + 1, -INF)); dp[0][0] = 0; for (int right = 0; right < n; right++) { for (int j = 1; j <= k; j++) { for (int left = 0; left <= right; left++) { if (left + 1 < j) continue; if (right - left + 1 > m) continue; ll add = abs(sums[right + 1] - sums[left]); ll np = add + dp[left][j - 1]; chmax(dp[right + 1][j], np); } } } ll up = 0; for (int i = 1; i <= k; i++) { chmax(up, dp[n][i]); } cout << up << endl; return 0; }