#include #include #include #include #include #include #include using namespace std; long long int cost(vector& c, int k, vector& stat, int rem, int p) { if(p==c.size()) { if(rem > 0) return numeric_limits::max(); return 0; } if(rem == 0) return 0; long long int res= cost(c,k,stat,rem,p+1); unordered_set pos; for(int i=max(0,p-k); i::max()) res1+=c[p]; for(auto i : pos) { stat[i]=1; } return min(res, res1); } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int b,k; cin >> b >> k; long long int tot=0; vector c(b); for(int i=0;i> c[i]; tot+=c[i]; } if(k>0) { vector stat(b,1); cout << cost(c,k,stat, c.size(),0); } else cout << tot; return 0; }