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;
#define ll long long
#define int long long
#define INF 1000000000
int n, k;
int a[100005];
int dp[105][100005];
signed main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
dp[1][i] = a[i];
for (int j = 1; j < i; j++) {
dp[1][i] = max(dp[1][i], a[j]);
}
}
for (int i = 2; i <= k; i++) {
for (int j = i; j <= n; j++) {
int max_val = 0;
dp[i][j] = INF;
for (int l = j; l >= i; l--) {
max_val = max(max_val, a[l]);
dp[i][j] = min(dp[i][j], dp[i-1][l-1] + max_val);
}
}
}
cout << dp[k][n] << endl;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |