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 = 1e5 + 10;
int n, k;
long long a[N], dp[N][101];
int main() {
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 0; i <= N - 1; i++) {
for(int j = 0; j <= 100; j++) dp[i][j] = 1e18;
}
dp[0][0] = 0;
long long mx = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= k; j++) {
mx = a[i];
for(int l = i - 1; l >= j - 1; l--) {
dp[i][j] = min(dp[i][j], dp[l][j - 1] + mx);
mx = max(mx, a[l]);
}
}
}
cout << dp[n][k] << "\n";
}
# | 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... |