#include using namespace std; #define MP make_pair const int MOD = 1e9 + 7; typedef long long LL; typedef pair PII; typedef long double LD; typedef vector VI; typedef vector VVI; #define all(x) (x).begin(), (x).end() #define bitCount __builtin_popcount const int N = 10005; const LL inf = (LL)1e14; const int inv2 = 500000004; LL dp[N]; int c[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> c[i]; } fill(dp, dp + n + 1, inf); dp[0] = 0; for (int i = 1; i <= n; ++i) { LL &cost = dp[min(n, i + k)]; cost = min(dp[max(0, i - k - 1)] + c[i], cost); } cout << dp[n]; return 0; }