#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
const int N = 100100;
const int K = 110;
int f[N][K], a[N], n, k;
void calc(int j, int l, int r, int optl, int optr){
if (l > r) return;
int md = (l + r) >> 1;
int mx = 0, mn = oo, ps = -1;
for (int i = min(md, optr); i >= optl; i--){
mx = max(mx, a[i]);
if (f[i - 1][j - 1] < oo &&
mn > f[i - 1][j - 1] + mx){
mn = f[i - 1][j - 1] + mx;
ps = i;
}
}
f[md][j] = mn;
calc(j, l, md - 1, optl, ps);
calc(j, md + 1, r, ps, optr);
}
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 <= k; j++)
f[i][j] = oo;
f[0][0] = 0;
for (int j = 1; j <= k; j++)
calc(j, 1, n, 1, n);
cout << f[n][k];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
4600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |