#include <iostream>
#include <set>
using namespace std;
const int MAXN = 5010;
int ans = 1e9;
int dp[MAXN][MAXN];
int arr[MAXN];
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
for(int i=0;i<=5000;i++){
if(i == 0){
dp[0][i] = 0;
}else{
dp[0][i] = 1e8;
}
}
for(int i=1;i<=n;i++){
multiset<int> s1;
for(int j=0;j<=5000;j++){
s1.insert(dp[i-1][j]);
}
for(int j=0;j<=5000;j++){
int lptr = j-m-1;
// cout<<j<<endl;
if(lptr>=0){
if(s1.size()){
if(s1.find(dp[i-1][lptr])!=s1.end()){
s1.erase(s1.find(dp[i-1][lptr]));
}
}
}
int hold = 0;
if(s1.size()){
hold = *s1.begin();
}
dp[i][j] = (int)hold;
if(arr[i] !=j){
dp[i][j]++;
}else{
// cout<<arr[i]<<endl;
}
}
}
//cout<<dp[3][700]<<endl;
for(int i=0;i<=5000;i++){
ans = min(ans,dp[n][i]);
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
4 ms |
632 KB |
Output is correct |
4 |
Correct |
9 ms |
760 KB |
Output is correct |
5 |
Correct |
9 ms |
732 KB |
Output is correct |
6 |
Correct |
9 ms |
760 KB |
Output is correct |
7 |
Correct |
10 ms |
732 KB |
Output is correct |
8 |
Correct |
10 ms |
760 KB |
Output is correct |
9 |
Correct |
8 ms |
760 KB |
Output is correct |
10 |
Correct |
9 ms |
760 KB |
Output is correct |
11 |
Correct |
10 ms |
760 KB |
Output is correct |
12 |
Correct |
9 ms |
764 KB |
Output is correct |
13 |
Correct |
9 ms |
760 KB |
Output is correct |
14 |
Correct |
9 ms |
760 KB |
Output is correct |
15 |
Correct |
9 ms |
760 KB |
Output is correct |
16 |
Correct |
9 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
4 ms |
632 KB |
Output is correct |
4 |
Execution timed out |
1066 ms |
31176 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
31112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
31112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |