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 <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <map>
#include <set>
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, K;
cin >> N >> K;
int64_t arr[N];
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
int64_t INF = 1e17;
int64_t dp[K + 1][N + 1];
for (int i = 0; i <= K; i++) {
for (int j = 0; j <= N; j++) {
dp[i][j] = INF;
}
}
for (int j = 1; j <= N; j++) {
dp[1][j] = 0;
for (int l = 0; l < j; l++) {
dp[1][j] = max(dp[1][j], arr[l]);
}
}
for (int i = 2; i <= K; i++) {
for (int j = 0; j <= N; j++) {
int64_t myMax = 0;
for (int l = j - 1; l >= 0; l--) {
myMax = max(myMax, arr[l]);
dp[i][j] = min(dp[i][j], dp[i - 1][l] + myMax);
}
}
}
cout << dp[K][N] << endl;
}
# | 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... |