#include #include #include #include #include #include using namespace std; int n,k; int cost[100000]; int dp[10000][10000]; int dp1[10000]; long long int rec(int start) { long long int mina = 10000000000; if(n-1 <= start+k) { int ans = cost[start]; for(int i=start+1;i cost[i]) ans = cost[i]; } return ans; } else if(dp1[start]!=-1) return dp1[start]; else { mina = cost[start] + rec(start + k + 1); for(int i=start+1;i<=start+k;i++) { if(!(mina <= cost[i])) mina = min(mina,cost[i] + rec(i+k+1)); } } return mina; } long long int recurr(int start,int end) { if(start>end) return 0; else if(end <= start + k) { long long int ans= cost[start]; for(int i=start + 1;i<=end;i++) { if(ans > cost[i]) ans = cost[i]; } return ans; } else if(dp[start][end] != -1) return dp[start][end]; long long int mina = 100000; for(int i=start;i<=start+k;i++) { for(int j=end-k;j<=end;j++) { if(i!=j) { if(!(cost[i]+cost[j] > mina)) mina = min(mina,cost[i]+cost[j]+recurr(i+k+1,j-k-1)); } else return cost[i]; } } return mina; } int main() { memset(dp1,-1,sizeof(dp1)); cin>>n>>k; for(int i=0;i>cost[i]; } cout<