#include <map>
#include <vector>
#include <iostream>
using namespace std;
const int inf = 2e9;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, K;
cin >> N >> K;
int dp[N][K];
int a[N];
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= K; j++) {
dp[i][j] = inf;
}
}
dp[0][0] = 0;
dp[1][1] = a[1];
for (int i = 2; i <= N; i++) {
dp[i][1] = max(dp[i - 1][1], a[i]);
}
auto getmax = [&](int l, int r) -> int {
int mx = a[l];
for (int i = l; i <= r; i++) {
mx = max(mx, a[i]);
}
return mx;
};
for (int k = 2; k <= K; k++) {
for (int i = 1; i <= N; i++) {
int mn = 2e9;
for (int j = 1; j <= i - 1; j++) {
mn = min(mn, dp[j][k - 1] + getmax(j + 1, i));
}
dp[i][k] = mn;
}
}
cout << dp[N][K] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |