#include #include #include #include #include using namespace std; static vector c; static int_fast16_t n, k; int_fast64_t mincost(int_fast16_t b, int_fast16_t e) { if (e < b + 1) return 0; if (e == b + 1) return c[b]; int_fast64_t mc = (int_fast64_t(1) << 63) - 1; int_fast64_t m; for (int_fast16_t kk = 0; kk < (e - b) && kk <= k; ++kk) { m = c[b + kk] + mincost(b + kk + k + 1, e); if (m < mc) mc = m; } return mc; } int main() { cin >> n >> k; cin.ignore(); c.resize(n); for (int_fast16_t i = 0; i < n; ++i) cin >> c[i]; cin.ignore(); cout << mincost(0, n) << endl; return 0; }