#include <bits/stdc++.h>
#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
const int inf = (int)1e9 + 7;
const int N = (int)1e5 + 7;
int n,k;
int a[N];
int dp[102][N];
int get (int l,int r) {
int mx = 0;
for (int i = l; i <= r; i ++)
mx = max(mx,a[i]);
return mx;
}
int main () {
cin >> n >> k;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
}
memset(dp,0x3f3f3f3f,sizeof(dp));
dp[1][1] = a[1];
dp[0][0] = 0;
for (int i = 1; i <= k; i ++) {
for (int j = 1; j <= n; j ++) {
for (int l = i - 1; l < j; l ++) {
dp[i][j] = min(dp[i][j],dp[i - 1][l] + get(l + 1,j));
}
}
}
cout << dp[k][n] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
42252 KB |
Output is correct |
2 |
Correct |
0 ms |
42252 KB |
Output is correct |
3 |
Correct |
0 ms |
42252 KB |
Output is correct |
4 |
Correct |
0 ms |
42252 KB |
Output is correct |
5 |
Correct |
0 ms |
42252 KB |
Output is correct |
6 |
Correct |
0 ms |
42252 KB |
Output is correct |
7 |
Correct |
6 ms |
42252 KB |
Output is correct |
8 |
Correct |
0 ms |
42252 KB |
Output is correct |
9 |
Correct |
0 ms |
42252 KB |
Output is correct |
10 |
Correct |
6 ms |
42252 KB |
Output is correct |
11 |
Correct |
6 ms |
42252 KB |
Output is correct |
12 |
Correct |
3 ms |
42252 KB |
Output is correct |
13 |
Correct |
0 ms |
42252 KB |
Output is correct |
14 |
Correct |
3 ms |
42252 KB |
Output is correct |
15 |
Correct |
3 ms |
42252 KB |
Output is correct |
16 |
Correct |
0 ms |
42252 KB |
Output is correct |
17 |
Correct |
3 ms |
42252 KB |
Output is correct |
18 |
Correct |
6 ms |
42252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
42252 KB |
Output is correct |
2 |
Correct |
9 ms |
42252 KB |
Output is correct |
3 |
Correct |
6 ms |
42252 KB |
Output is correct |
4 |
Correct |
3 ms |
42252 KB |
Output is correct |
5 |
Correct |
6 ms |
42252 KB |
Output is correct |
6 |
Correct |
0 ms |
42252 KB |
Output is correct |
7 |
Correct |
3 ms |
42252 KB |
Output is correct |
8 |
Correct |
0 ms |
42252 KB |
Output is correct |
9 |
Correct |
0 ms |
42252 KB |
Output is correct |
10 |
Correct |
13 ms |
42252 KB |
Output is correct |
11 |
Correct |
13 ms |
42252 KB |
Output is correct |
12 |
Correct |
0 ms |
42252 KB |
Output is correct |
13 |
Correct |
0 ms |
42252 KB |
Output is correct |
14 |
Correct |
6 ms |
42252 KB |
Output is correct |
15 |
Correct |
0 ms |
42252 KB |
Output is correct |
16 |
Correct |
3 ms |
42252 KB |
Output is correct |
17 |
Correct |
6 ms |
42252 KB |
Output is correct |
18 |
Correct |
0 ms |
42252 KB |
Output is correct |
19 |
Correct |
3 ms |
42252 KB |
Output is correct |
20 |
Correct |
3 ms |
42252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
42252 KB |
Output is correct |
2 |
Correct |
3 ms |
42252 KB |
Output is correct |
3 |
Correct |
3 ms |
42252 KB |
Output is correct |
4 |
Correct |
0 ms |
42252 KB |
Output is correct |
5 |
Correct |
9 ms |
42252 KB |
Output is correct |
6 |
Correct |
3 ms |
42252 KB |
Output is correct |
7 |
Correct |
0 ms |
42252 KB |
Output is correct |
8 |
Correct |
0 ms |
42252 KB |
Output is correct |
9 |
Correct |
6 ms |
42252 KB |
Output is correct |
10 |
Correct |
6 ms |
42252 KB |
Output is correct |
11 |
Correct |
3 ms |
42252 KB |
Output is correct |
12 |
Correct |
0 ms |
42252 KB |
Output is correct |
13 |
Correct |
6 ms |
42252 KB |
Output is correct |
14 |
Correct |
6 ms |
42252 KB |
Output is correct |
15 |
Correct |
13 ms |
42252 KB |
Output is correct |
16 |
Correct |
13 ms |
42252 KB |
Output is correct |
17 |
Correct |
3 ms |
42252 KB |
Output is correct |
18 |
Correct |
6 ms |
42252 KB |
Output is correct |
19 |
Correct |
3 ms |
42252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
42252 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |