#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5002;
int dp[N][N], a[N];
int n, k;
int f(int idx, int k){
if(k < 0) return 1e18;
if(idx > n) return 0;
int &cur = dp[idx][k];
if(cur != -1) return cur;
cur = 1e18;
for(int i = idx; i <= n; i++){
cur = min(cur, f(i + 1, k - 1) + a[i] - a[idx] + 1);
}
return cur;
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
cout << f(1, k) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
196044 KB |
Output is correct |
2 |
Correct |
69 ms |
196096 KB |
Output is correct |
3 |
Correct |
70 ms |
196040 KB |
Output is correct |
4 |
Correct |
70 ms |
196044 KB |
Output is correct |
5 |
Correct |
72 ms |
196172 KB |
Output is correct |
6 |
Correct |
71 ms |
196096 KB |
Output is correct |
7 |
Correct |
72 ms |
196148 KB |
Output is correct |
8 |
Correct |
70 ms |
196044 KB |
Output is correct |
9 |
Correct |
73 ms |
196152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
196044 KB |
Output is correct |
2 |
Correct |
69 ms |
196096 KB |
Output is correct |
3 |
Correct |
70 ms |
196040 KB |
Output is correct |
4 |
Correct |
70 ms |
196044 KB |
Output is correct |
5 |
Correct |
72 ms |
196172 KB |
Output is correct |
6 |
Correct |
71 ms |
196096 KB |
Output is correct |
7 |
Correct |
72 ms |
196148 KB |
Output is correct |
8 |
Correct |
70 ms |
196044 KB |
Output is correct |
9 |
Correct |
73 ms |
196152 KB |
Output is correct |
10 |
Correct |
382 ms |
196216 KB |
Output is correct |
11 |
Execution timed out |
1100 ms |
196172 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
196044 KB |
Output is correct |
2 |
Correct |
69 ms |
196096 KB |
Output is correct |
3 |
Correct |
70 ms |
196040 KB |
Output is correct |
4 |
Correct |
70 ms |
196044 KB |
Output is correct |
5 |
Correct |
72 ms |
196172 KB |
Output is correct |
6 |
Correct |
71 ms |
196096 KB |
Output is correct |
7 |
Correct |
72 ms |
196148 KB |
Output is correct |
8 |
Correct |
70 ms |
196044 KB |
Output is correct |
9 |
Correct |
73 ms |
196152 KB |
Output is correct |
10 |
Correct |
382 ms |
196216 KB |
Output is correct |
11 |
Execution timed out |
1100 ms |
196172 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |