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 INF = 1e9;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int N, K;
cin >> N >> K;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
vector<vector<int>> dp(K + 1, vector<int>(N + 1, INF));
dp[0][0] = 0;
for (int i = 1; i <= K; i++) {
for (int j = i; j <= N; j++) {
int maxi = 0;
for (int k = j; k >= i; k--) {
maxi = max(maxi, a[k - 1]);
dp[i][j] = min(dp[i][j], dp[i - 1][k - 1] + maxi);
}
}
}
cout << dp[K][N] << '\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |