#include typedef long long int lld; lld costs[10001]; lld preCompute[10001]; lld costToTurnOff(int N, int K) { int k; lld cost, startCost; if (N <= 0) { return 0; } if (preCompute[N] >= 0) { return preCompute[N]; } startCost = costs[N] + costToTurnOff(N-K-1,K); for (k=N-K; k < N; ++k) { if (k <= 0) { continue; } cost = costs[k] + costToTurnOff(k-K-1,K); if (cost < startCost) { startCost = cost; } } return (preCompute[N] = startCost); } int main() { int n,k,N,K; if (2 != scanf("%d %d", &N, &K)) { return 1; } for (n=0; n <= N; ++n) { preCompute[n] = -1; } for (n=1; n <= N; ++n) { scanf("%lld", costs+n); } printf("%lld\n", costToTurnOff(N,K)); }