// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using ll = long long; const ll inf = 1LL << 60; using S = ll; S op(S l, S r){ return max(l, r); } S e(){ return -inf; } using F = ll; S mapping(F f, S x){ return f + x; } F composition(F l, F r){ return l + r; } F id(){ return 0; } void solve(){ int n, k; cin >> n >> k; vector A(n); for(auto &a : A) cin >> a; lazy_segtree seg(n + 1); seg.set(0, 0); for(int i = 1; i <= n; i++){ ll a = A[i - 1]; seg.set(i, seg.prod(0, i)); seg.apply(max(0, i - k + 1), i, a); } cout << seg.all_prod() << endl; } int main(){ cin.tie(0)->sync_with_stdio(0); int t; t = 1; // cin >> t; while(t--) solve(); }