#include #include #include #include #include using namespace std; typedef long long ll; const ll INF = (1LL << 50); int main() { int n, k; scanf("%d%d", &n, &k); vector a(n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } vector dp1(n); vector dp2(n); for (int i = 0; i < n; ++i) { ll curDp; if (i <= k) { curDp = 0; } else { curDp = INF; for (int j = 2 * k + 1; j <= i && j <= 2 * k + 1; ++j) { curDp = min(curDp, dp1[i - j]); } } dp1[i] = curDp + a[i]; //dp1[i] = a[i] + (i <= k ? 0 : dp2[i - k - 1]); dp2[i] = INF; for (int j = 0; j <= k && j <= i; ++j) { dp2[i] = min(dp2[i], dp1[i - j]); } } printf("%lld\n", dp2[n - 1]); return 0; }