#include <bits/stdc++.h>
using namespace std;
const int N = 3005, oo = 1e9;
int n, k, a[N], dp[N][N];
int main() {
cin >> n >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
for(int i = 0; i < N; ++i) {
for(int j = 0; j < N; ++j) {
dp[i][j] = oo;
}
}
dp[0][0] = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= min(i, k); ++j) {
int maximum = a[i];
for(int p = i - 1; p >= 0; --p) {
maximum = max(maximum, a[p]);
dp[i][j] = min(dp[i][j], dp[p][j - 1] + maximum);
}
}
}
cout << dp[n][k] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
35704 KB |
Output is correct |
2 |
Correct |
22 ms |
35712 KB |
Output is correct |
3 |
Correct |
22 ms |
35704 KB |
Output is correct |
4 |
Correct |
23 ms |
35712 KB |
Output is correct |
5 |
Incorrect |
23 ms |
35832 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
35712 KB |
Output is correct |
2 |
Correct |
24 ms |
35704 KB |
Output is correct |
3 |
Correct |
22 ms |
35712 KB |
Output is correct |
4 |
Correct |
23 ms |
35712 KB |
Output is correct |
5 |
Incorrect |
22 ms |
35840 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
35704 KB |
Output is correct |
2 |
Correct |
22 ms |
35712 KB |
Output is correct |
3 |
Correct |
22 ms |
35704 KB |
Output is correct |
4 |
Correct |
23 ms |
35712 KB |
Output is correct |
5 |
Incorrect |
23 ms |
35832 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
35704 KB |
Output is correct |
2 |
Correct |
22 ms |
35712 KB |
Output is correct |
3 |
Correct |
22 ms |
35704 KB |
Output is correct |
4 |
Correct |
23 ms |
35712 KB |
Output is correct |
5 |
Incorrect |
23 ms |
35832 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |