This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
const int N=5e3+5;
int dp[N][N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
vector <int> a(n);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<=5000;i++){
if(i!=a[0])dp[0][i]=1;
if(i>m)dp[0][i]+=1e9;
}
for(int i=0;i<=5000;i++){
}
for(int i=1;i<n;i++){
int mn=1e9;
int ind=5000-m;
for(int j=5000;j>=ind;j--){
mn=min(mn,dp[i-1][j]);
}
for(int j=5000;j>=0;j--){
if(j!=a[i])dp[i][j]=mn+1;
else dp[i][j]=mn;
ind--;
if(ind>=0)mn=min(mn,dp[i-1][ind]);
}
}
int ans=1e9;
for(int i=0;i<=5000;i++){
ans=min(ans,dp[n-1][i]);
}
cout<<ans<<"\n";
}
/*
5 400
300
700
200
1000
500
3 300
700
1000
1300
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |