#include <bits/stdc++.h>
using namespace std;
long long n,k;
long long dp[5005][5005];
long long x[5005];
long long f(long long idx,long long p)
{
if(idx==n+1)return 0;
if(p==0)return 1e18;
if(dp[idx][p]!=1e18)
{
return dp[idx][p];
}
long long rez=1e18;
for(long long i=idx;i<=n;i++)
{
if(p-1>=0)
{
rez=min(rez, f(i+1,p-1)+x[i]-x[idx]+1);
}
}
return dp[idx][p]=rez;
}
int main()
{
ios_base::sync_with_stdio(false);
cin>>n>>k;
for(long long i=1;i<=n;i++)
{
cin>>x[i];
}
for(long long i=0;i<=n;i++)
{
for(long long j=0;j<=k;j++)
{
dp[i][j]=1e18;
}
}
cout<<f(1,k)<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
395 ms |
12840 KB |
Output is correct |
11 |
Execution timed out |
1086 ms |
14964 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
395 ms |
12840 KB |
Output is correct |
11 |
Execution timed out |
1086 ms |
14964 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |