#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define mod 998244353 using namespace std; typedef pair P; // range-add, range-min query struct LazySegTree{ int size; vector seg, seg2, delay; LazySegTree(){} LazySegTree(int size){ this->size = size; seg.resize(1<<(size+1)); seg2.resize(1<<(size+1)); delay.resize(1<<(size+1)); } void init() { for(int i = 0; i < (1<<(size+1)); i++){ seg[i] = -inf, seg2[i] = -inf; delay[i] = 0; } } void eval(int l, int r, int k) { if(delay[k]){ seg[k] += delay[k]; //総和クエリのときは区間幅を乗じる必要がある seg2[k] -= delay[k]; //総和クエリのときは区間幅を乗じる必要がある if(l < r){ delay[(k<<1)] += delay[k]; delay[(k<<1)+1] += delay[k]; } delay[k] = 0; } } void update(int i, llint val) { int l = 0, r = (1<= 0; j--){ k <<= 1; if(i & (1<>1; } else l = ((l+r)>>1)+1; eval(l, r, k); } i += (1 << size); seg[i] = seg2[i] = val; while(i > 1){ i >>= 1; seg[i] = max(seg[(i<<1)], seg[(i<<1)+1]); seg2[i] = max(seg2[(i<<1)], seg2[(i<<1)+1]); } } void add(int a, int b, int k, int l, int r, llint val) { eval(l, r, k); if(b < l || r < a) return; if(a <= l && r <= b){ delay[k] += val; eval(l, r, k); return; } add(a, b, (k<<1), l, (l+r)>>1, val); add(a, b, (k<<1)+1, ((l+r)>>1)+1, r, val); seg[k] = max(seg[(k<<1)], seg[(k<<1)+1]); seg2[k] = max(seg2[(k<<1)], seg2[(k<<1)+1]); } void add(int a, int b, llint val){ if(a > b) return; add(a, b, 1, 0, (1<> n >> k >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 0; i < 2; i++){ seg[i] = LazySegTree(12), seg[i].init(); } seg[0].update(0, 0); for(int i = 1; i <= k; i++){ if(i <= 2) seg[i&1].update(0, -inf); for(int j = 1; j <= n; j++){ seg[(i-1)&1].add(0, j-1, a[j]); llint tmp = seg[(i-1)&1].query(max(0, j-m), j-1); seg[i&1].update(j, tmp); } } cout << seg[k&1].query(n, n) << endl; return 0; }