#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int arr[maxn];
int dp[maxn][maxn];
void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> arr[i];
m = min(m, n);
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
for (int k = i-1; k >= j-1; k--)
dp[i][j] = min(dp[i][j], dp[k][j-1] + (arr[i]-arr[k+1]+1));
cout << dp[n][m] << '\n';
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
98244 KB |
Output is correct |
2 |
Correct |
40 ms |
98324 KB |
Output is correct |
3 |
Correct |
41 ms |
98364 KB |
Output is correct |
4 |
Correct |
40 ms |
98308 KB |
Output is correct |
5 |
Correct |
41 ms |
98348 KB |
Output is correct |
6 |
Correct |
41 ms |
98312 KB |
Output is correct |
7 |
Correct |
41 ms |
98348 KB |
Output is correct |
8 |
Correct |
42 ms |
98292 KB |
Output is correct |
9 |
Correct |
41 ms |
98328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
98244 KB |
Output is correct |
2 |
Correct |
40 ms |
98324 KB |
Output is correct |
3 |
Correct |
41 ms |
98364 KB |
Output is correct |
4 |
Correct |
40 ms |
98308 KB |
Output is correct |
5 |
Correct |
41 ms |
98348 KB |
Output is correct |
6 |
Correct |
41 ms |
98312 KB |
Output is correct |
7 |
Correct |
41 ms |
98348 KB |
Output is correct |
8 |
Correct |
42 ms |
98292 KB |
Output is correct |
9 |
Correct |
41 ms |
98328 KB |
Output is correct |
10 |
Execution timed out |
1094 ms |
98352 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
98244 KB |
Output is correct |
2 |
Correct |
40 ms |
98324 KB |
Output is correct |
3 |
Correct |
41 ms |
98364 KB |
Output is correct |
4 |
Correct |
40 ms |
98308 KB |
Output is correct |
5 |
Correct |
41 ms |
98348 KB |
Output is correct |
6 |
Correct |
41 ms |
98312 KB |
Output is correct |
7 |
Correct |
41 ms |
98348 KB |
Output is correct |
8 |
Correct |
42 ms |
98292 KB |
Output is correct |
9 |
Correct |
41 ms |
98328 KB |
Output is correct |
10 |
Execution timed out |
1094 ms |
98352 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |