#include #include #include #include #include #include #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; template class lazy_segment_tree{ int n; T fval; vector dat, lazy; public: lazy_segment_tree(){ } lazy_segment_tree(int n_, T val){ init(n_, val); } ~lazy_segment_tree(){ } void init(int n_, T val){ fval = val; n = 1; while(n < n_) n *= 2; dat.resize(2 * n - 1); lazy.resize(2 * n - 1, fval); for(int i = 0; i < 2 * n - 1; i++) dat[i] = fval; } void eval(int k, int l, int r){ if(lazy[k] != fval){ dat[k] = dat[k] + lazy[k]/(r - l); if(r - l > 1) { lazy[2*k+1] = lazy[2*k+1] + lazy[k]/2; lazy[2*k+2] = lazy[2*k+2] + lazy[k]/2; } lazy[k] = 0; } } void update(int a, int b, T x, int k = 0, int l = 0, int r = -1){ if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) {return ;} if(a <= l && r <= b){ lazy[k] = lazy[k] + (r - l) * x; eval(k, l, r); } else { update(a, b, x, 2*k+1, l, (l+r)/2); update(a, b, x, 2*k+2, (l+r)/2, r); dat[k] = max(dat[2*k+1], dat[2*k+2]); } } T query(int a, int b, int k = 0, int l = 0, int r = -1){ if(r < 0) r = n; eval(k, l, r); if(r <= a || b <= l){ return -INF; } if(a <= l && r <= b){ return dat[k]; }else { T vl = query(a, b, k * 2 + 1, l, (l + r) / 2 ); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } }; signed main(){ cout< A; vector sum; vector> dp; cin>>N>>K>>M; A.resize(N); dp.resize(N+1, vector(K+1, -INF)); sum.resize(N+1); for(int i = 0; i < N; i++){ cout<>A[i]; sum[i+1] = sum[i] + A[i]; if(i < M) dp[i][1] = abs(sum[i+1]); cout<<"i = "< lseg, lseg2; lseg.init(N+2, 0); lseg2.init(N+2, 0); for(int i = 0; i < N; i++){ lseg.update(i, i+1, dp[i][j-1]); lseg2.update(i, i+1, dp[i][j-1]); } for(int i = j-1; i < N; i++){ lseg.update(j-2, i, A[i]); lseg2.update(j-2, i, -A[i]); dp[i][j] = max(-INF, max(lseg.query(max(j-2, i - M), i), lseg2.query(max(j-2, i - M), i))); } } cout<