#include using namespace std; #define LL long long #define F first #define S second #define MP make_pair #define PB push_back #define SZ(a) (int)(a.size()) #define BS(vec,val) (int)(lower_bound(vec.begin(),vec.end(),val) - vec.begin()) #define bitcount __builtin_popcountll #define LET(it,container) __typeof(container.begin()) it(container.begin()) #define ITER(it,container) for(__typeof(container.begin()) it=container.begin();it!=container.end();it++) #define PREC cout << setprecision(10) << fixed; #define FIO ios_base::sync_with_stdio(0); cin.tie(NULL); #define DB(x) cerr << #x << ": " << x << " "; //-std=c++11 //#define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::endl; } template void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif //FILE *fin = freopen("in","r",stdin); //FILE *fout = freopen("out","w",stdout); #define endl "\n" const double PI = acos(-1.0); const int MOD = 1e9 + 7; const LL INF = 1e15 + 9; const int MX = 1e4 + 5; int n,k; LL inp[MX]; LL dp[MX]; LL solve(int idx) { if(idx > n) return 0; if(dp[idx] != -1) return dp[idx]; LL ret = INF; int cnt = 0; for(int i=idx;i<=n;i++) { if(cnt > k) break; ret = min(ret,solve(i+k+1) + inp[i]); cnt++; } return dp[idx] = ret; } int main() { FIO; cin >> n; cin >> k; for(int i=1;i<=n;i++) cin >> inp[i]; memset(dp,-1,sizeof dp); cout << solve(1) << endl; return 0; }