This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 1e3 + 1;
const int inf = 1e9 + 7;
int dp[N][N];
signed main() {
int n, k;
cin >> n >> k;
vector <int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = inf;
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
for (int c = i; c < n; c++) {
dp[c + 1][j + 1] = min(
dp[i][j] + v[c] - v[i] + 1,
dp[c + 1][j + 1]
);
}
}
}
cout << dp[n][k] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |