#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <int, pi>
#define vi vector <int>
const ll mod = 1e9 + 7;
int n, k, dp[5001][5001], t[5005];
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
cin>>n>>k;
for(int i=1; i<=n; i++) cin>>t[i];
for(int i=1; i<=n; i++){
for(int j=1; j<=k; j++) dp[i][j]=1e9;
}
dp[1][1]=1;
for(int i=2; i<=n; i++) dp[i][1]=t[i]-t[1]+1;
for(int i=1; i<=n; i++){
for(int cnt=2; cnt<=min(i, k); cnt++){
dp[i][cnt]=min(dp[i-1][cnt-1]+1, dp[i-1][cnt]+t[i]-t[i-1]);
}
}
/*for(int i=1; i<=n; i++){
for(int j=1; j<=k; j++) cout<<dp[i][j]<<" ";cout<<endl;
}*/
cout<<dp[n][k];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
12 ms |
12664 KB |
Output is correct |
11 |
Correct |
13 ms |
13688 KB |
Output is correct |
12 |
Correct |
25 ms |
24184 KB |
Output is correct |
13 |
Correct |
38 ms |
35960 KB |
Output is correct |
14 |
Correct |
47 ms |
46456 KB |
Output is correct |
15 |
Correct |
48 ms |
47480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
12 ms |
12664 KB |
Output is correct |
11 |
Correct |
13 ms |
13688 KB |
Output is correct |
12 |
Correct |
25 ms |
24184 KB |
Output is correct |
13 |
Correct |
38 ms |
35960 KB |
Output is correct |
14 |
Correct |
47 ms |
46456 KB |
Output is correct |
15 |
Correct |
48 ms |
47480 KB |
Output is correct |
16 |
Runtime error |
103 ms |
43200 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Halted |
0 ms |
0 KB |
- |