#include using namespace std; #define F first #define S second #define pb push_back #define mp make_pair #define var(X) cerr << " --> " << #X << " = " << X << endl #define arr(a,n) for(int i=0;i vi; typedef pair ii; typedef vector > vii; const double eps = 1e-10, pi = acos(-1.0); ll dp[10004],a[10005]; int main() { /* #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("out.txt","w",stdout); #endif */ int t=1,cs=1; //ios_base::sync_with_stdio(0); cin.tie(0); //clock_t start=clock(); //scanf("%d",&t); while(t--) { int n,k,x,y; cin>>n>>k; for(int i=1;i<=n;i++) { cin>>a[i]; dp[i]=LLONG_MAX; } dp[0]=0; for(int i=1;i<=n;i++) { dp[i]=min(dp[i],a[i]+dp[max(0,i-k-1)]); for(int j=1;j<=k;j++) dp[i+j]=min(dp[i+j],a[i]+dp[max(0,i-k-1)]); } /*for(int i=1;i<=n;i++) cout<