#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define fi first
#define sec second
const ll MOD = 1e9 + 7;
const ll N = 5e3 + 5;
const ll INF = 1e18;
ll dp[N][N];
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
// cin >> tc;
while(tc--){
ll n,k; cin >> n >> k;
vector<ll>vec(n+5);
for(int i=1;i<=n;i++) cin >> vec[i];
for(int i=0;i<=n;i++){
for(int j=0;j<=k;j++){
dp[i][j] = -INF;
}
}
dp[0][0] = 0;
for(int i=1;i<=n;i++){
for(int j=0;j<k;j++){
dp[i][j] = dp[i-1][j];
if(j) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + (vec[i] - vec[i-1] - 1));
}
}
ll ans = -INF;
for(int i=0;i<k;i++) ans = max(ans, dp[n][i]);
cout << vec[n] - vec[1] + 1 - ans << endl;
}
}
/*
1 2 3 4 5
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
408 KB |
Output is correct |
10 |
Correct |
5 ms |
14684 KB |
Output is correct |
11 |
Correct |
6 ms |
16732 KB |
Output is correct |
12 |
Incorrect |
15 ms |
37468 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
408 KB |
Output is correct |
10 |
Correct |
5 ms |
14684 KB |
Output is correct |
11 |
Correct |
6 ms |
16732 KB |
Output is correct |
12 |
Incorrect |
15 ms |
37468 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |