#include <bits/stdc++.h>
using namespace std;
int n;
int a[1001000];
int k;
int can(int x,int y)
{
if(x>=y)
return 1;
if(y-x<=k)
return 1;
return 0;
}
int dp[5010][5010];
int f(int i,int j)
{
if(dp[i][j]!=-1)
return dp[i][j];
dp[i][j]=10000000;
if(i==n-1)
{
return 1-can(j,a[i]);
}
int mn=10101010;
for(int v=0;v<=1000;v++)
{//cout<<" "<<j<<" "<<i<<" "<<v<<endl;
if(can(j,v))
{
mn=min(mn,f(i+1,v)+(v!=a[i]));
}
}
return dp[i][j]=mn;
}
int main()
{
memset(dp,-1,sizeof dp);
cin>>n>>k;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<f(0,0)<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
98512 KB |
Output is correct |
2 |
Correct |
36 ms |
98448 KB |
Output is correct |
3 |
Correct |
36 ms |
98524 KB |
Output is correct |
4 |
Correct |
35 ms |
98436 KB |
Output is correct |
5 |
Correct |
36 ms |
98524 KB |
Output is correct |
6 |
Correct |
41 ms |
98504 KB |
Output is correct |
7 |
Correct |
36 ms |
98464 KB |
Output is correct |
8 |
Incorrect |
37 ms |
98444 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
98512 KB |
Output is correct |
2 |
Correct |
36 ms |
98448 KB |
Output is correct |
3 |
Correct |
36 ms |
98524 KB |
Output is correct |
4 |
Correct |
35 ms |
98436 KB |
Output is correct |
5 |
Correct |
36 ms |
98524 KB |
Output is correct |
6 |
Correct |
41 ms |
98504 KB |
Output is correct |
7 |
Correct |
36 ms |
98464 KB |
Output is correct |
8 |
Incorrect |
37 ms |
98444 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
98512 KB |
Output is correct |
2 |
Correct |
36 ms |
98448 KB |
Output is correct |
3 |
Correct |
36 ms |
98524 KB |
Output is correct |
4 |
Correct |
35 ms |
98436 KB |
Output is correct |
5 |
Correct |
36 ms |
98524 KB |
Output is correct |
6 |
Correct |
41 ms |
98504 KB |
Output is correct |
7 |
Correct |
36 ms |
98464 KB |
Output is correct |
8 |
Incorrect |
37 ms |
98444 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
98512 KB |
Output is correct |
2 |
Correct |
36 ms |
98448 KB |
Output is correct |
3 |
Correct |
36 ms |
98524 KB |
Output is correct |
4 |
Correct |
35 ms |
98436 KB |
Output is correct |
5 |
Correct |
36 ms |
98524 KB |
Output is correct |
6 |
Correct |
41 ms |
98504 KB |
Output is correct |
7 |
Correct |
36 ms |
98464 KB |
Output is correct |
8 |
Incorrect |
37 ms |
98444 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |