#include #if __has_include() #include using namespace atcoder; #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; ll op(ll a, ll b) { return min(a, b); } ll e() { return 1e18; } int main() { int n, k; cin >> n >> k; vector a(n); rep(i, n) cin >> a[i]; ll ans = 0; rep(i, n) ans += a[i]; segtree t(n); rep(i, k) t.set(i, a[i]); for (int i = k; i < n; ++i) { ll now = t.prod(i-k, i)+a[i]; t.set(i, now); } ans -= t.prod(n-k, n); cout << ans << '\n'; return 0; }