# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1179327 | shirokito | Stove (JOI18_stove) | C++20 | 1102 ms | 198044 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define el '\n'
const int N = 5000 + 24;
int n, k;
ll a[N], dp[N][N];
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
for (int i2 = 1; i2 <= i; i2++) {
dp[i][j] = min(dp[i][j], dp[i2 - 1][j - 1] + (a[i] - a[i2] + 1));
}
}
}
cout << dp[n][k] << el;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task "file"
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int T = 1; // cin >> T;
while (T--) solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |