#include using namespace std; template struct StarrySky { int n, n_org; T e; vector dat, added; typedef function Func; Func f; StarrySky(){} StarrySky(int n_input, Func f_input, T e_input){ initialize(n_input, f_input, e_input); } void initialize(int n_input, Func f_input, T e_input){ n_org = n_input; f = f_input; e = e_input; n = 1; while(n < n_input) n <<= 1; dat.assign(2*n-1, e); added.assign(2*n-1, 0); } void build(vector& A){ for(int k=0; k=0; k--) dat[k] = f(dat[2*k+1], dat[2*k+2]); } void add_between(int a, int b, T x){ add(a, b+1, x, 0, 0, n); } void add(int a, int b, T x, int k, int lb, int rb){ if(b <= lb || rb <= a) return; if(a <= lb && rb <= b){ added[k] += x; }else{ int mb = (lb+rb)>>1; add(a, b, x, 2*k+1, lb, mb); add(a, b, x, 2*k+2, mb, rb); dat[k] = f(dat[2*k+1] + added[2*k+1], dat[2*k+2] + added[2*k+2]); } } T between(int a, int b){ return query(a, b+1, 0, 0, n); } T query(int a, int b, int k, int l, int r){ if(r<=a || b<=l) return e; if(a<=l && r<=b) return dat[k] + added[k]; T vl = query(a, b, 2*k+1, l, (l+r)/2); T vr = query(a, b, 2*k+2, (l+r)/2, r); return f(vl, vr) + added[k]; } }; int main(){ int N, K, M; cin >> N >> K >> M; vector A(N); for(int i=0; i> A[i]; StarrySky st[3001][2]; vector init(N+1, -1e15); for(int k=0; k<=K; k++) for(int l=0; l<2; l++){ st[k][l].initialize(N+1, [](auto a, auto b){ return max(a, b); }, -1e18); st[k][l].build(init); } for(int l=0; l<2; l++) st[0][l].add_between(0, 0, 1e15); for(int i=0; i