#include <bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int t[1001000];
int f(int i,int k)
{
//cout<<" "<<i<<" "<<k<<endl;
if(dp[i][k]!=-1)
return dp[i][k];
if(k<=0)
return 1000000000;
if(i==0)
return 1;
return dp[i][k]=min(f(i-1,k-1)+1,f(i-1,k)+t[i]+1-t[i-1]);
}
int main()
{
int n,k;
cin>>n>>k;
memset(dp,-1,sizeof dp);
for(int i=0;i<n;i++)
cin>>t[i];
cout<<f(n-1,k)-n+k;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4172 KB |
Output is correct |
2 |
Correct |
2 ms |
4300 KB |
Output is correct |
3 |
Correct |
2 ms |
4172 KB |
Output is correct |
4 |
Correct |
3 ms |
4184 KB |
Output is correct |
5 |
Correct |
2 ms |
4228 KB |
Output is correct |
6 |
Correct |
2 ms |
4300 KB |
Output is correct |
7 |
Correct |
2 ms |
4172 KB |
Output is correct |
8 |
Correct |
2 ms |
4172 KB |
Output is correct |
9 |
Correct |
2 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4172 KB |
Output is correct |
2 |
Correct |
2 ms |
4300 KB |
Output is correct |
3 |
Correct |
2 ms |
4172 KB |
Output is correct |
4 |
Correct |
3 ms |
4184 KB |
Output is correct |
5 |
Correct |
2 ms |
4228 KB |
Output is correct |
6 |
Correct |
2 ms |
4300 KB |
Output is correct |
7 |
Correct |
2 ms |
4172 KB |
Output is correct |
8 |
Correct |
2 ms |
4172 KB |
Output is correct |
9 |
Correct |
2 ms |
4172 KB |
Output is correct |
10 |
Runtime error |
7 ms |
8524 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4172 KB |
Output is correct |
2 |
Correct |
2 ms |
4300 KB |
Output is correct |
3 |
Correct |
2 ms |
4172 KB |
Output is correct |
4 |
Correct |
3 ms |
4184 KB |
Output is correct |
5 |
Correct |
2 ms |
4228 KB |
Output is correct |
6 |
Correct |
2 ms |
4300 KB |
Output is correct |
7 |
Correct |
2 ms |
4172 KB |
Output is correct |
8 |
Correct |
2 ms |
4172 KB |
Output is correct |
9 |
Correct |
2 ms |
4172 KB |
Output is correct |
10 |
Runtime error |
7 ms |
8524 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |