p183.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n, m;
vector<int> a;

void read() {
    cin >> n >> m;
    a.resize(n);
    cin >> a;
}

void solve() {
    vector<vector<int>> dp(n, vector<int>(m + 1, (int)1e9));
    for(int i = 0; i < m - 1; i++) {
        dp[i][i + 1] = a[i];
    }

    int ans = (int)1e9;
    for(int i = 0; i < n; i++) {
        for(int prv_dist = 1; prv_dist <= m; prv_dist++) {
            for(int dist = 1; dist <= m; dist++) {
                int nxt = i + dist;
                if(nxt < n && prv_dist + dist <= m) {
                    dp[nxt][dist] =
                        min(dp[nxt][dist], dp[i][prv_dist] + a[nxt]);
                }
            }

            int left_to_end = n - i;
            if(prv_dist + left_to_end <= m) {
                ans = min(ans, dp[i][prv_dist]);
            }
        }
    }

    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

=================
statement.txt
======================
183. Painting the balls
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard input
output: standard output



Petya puts the N white balls in a line and now he wants to paint some of them in black, so that at least two black balls could be found among any M successive balls. Petya knows that he needs Ci milliliters of dye exactly to paint the i-th ball. Your task is to find out for Petya the minimum amount of dye he will need to paint the balls.

Input
The first line contains two integer numbers N and M (2<=N<=10000, 2<=M<=100, M<=N). The second line contains N integer numbers C1, C2, ..., CN (1<=Ci<=10000).

Output
Output only one integer number - the minimum amount of dye Petya will need (in milliliters).

Sample test(s)

Input
6 3
1 5 6 2 1 3

Output
9

Note
Example note: 1, 2, 4, 5 balls must be painted.
Author:	Andrew V. Lazarev
Resource:	ACM International Collegiate Programming Contest 2003-2004
North-Eastern European Region, Southern Subregion
Date:	2003 October, 9

=================
