/* ye mera template hai apna khud likho bc :P */ /* Author : Sarvagya Agarwal */ #include using namespace std; //defines #define openin freopen("input.txt","r",stdin) #define openout freopen("output.txt","w",stdout) #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define ll long long #define int long long #define mod 1000000007 #define rep(i,x,y) for (__typeof(x) i=x;i<=y;i++) #define all(c) (c).begin(),(c).end() #define ff first #define ss second #define pb push_back #define mp make_pair int power(int a , int b) { int res = 1 ; while(b) { if(b%2) { res = (res * a)%mod ; } b/=2 ; a = (a*a)%mod ; } return res ; } //debug #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 int n , k ; const int inf = 1e18 ; int dp[10005][2] , arr[10005] ; int32_t main() { fast; cin >> n >> k ; rep(i,1,n)cin >> arr[i] ; dp[0][0] = dp[0][1] = 0 ; for(int i = 1 ; i <= n ;++i) { int min_cost = inf ; for(int j = max(1ll,i-k) ; j < i ; ++j) { min_cost = min(min_cost,dp[j][1]) ; } dp[i][0] = min_cost ; dp[i][1] = arr[i] ; if(i-k > 1ll) { dp[i][1] += min(dp[i-k-1][0],dp[i-k-1][1]) ; } } cout << min(dp[n][0],dp[n][1]) << endl; return 0; }