#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];
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--) {
if(dp[i][j] != 0) dp[i][j] = min(dp[i][j], dp[l][j - 1] + mx);
if(dp[i][j] == 0) dp[i][j] = dp[l][j - 1] + mx;
mx = max(mx, a[l]);
}
}
}
cout << dp[n][k] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |