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>
using namespace std;
typedef long long ll;
typedef pair<int,ll> ii;
const int MAX_N=3e5+10;
vector<ll> x;
ll val[7010];
int n,d;
int dp[7010][7010];
int report(int id,ll ma){
if(dp[id][ma]!=-1) return dp[id][ma];
if(id==n) return 0;
int r;
if(id==0) r=n;
else r=min(n,id+d);
int ans=0;
for(int i=id+1;i<=r;i++){
ll nma=max(ma,val[i]);
bool sw=(val[i]>ma);
ans=max(ans,report(i,nma)+sw);
}
return dp[id][ma]=ans;
}
int main(){
memset(dp,-1,sizeof dp);
cin>>n>>d;
x.push_back(-1);
set<int> comp;
for(int i=0;i<n;i++){
ll a; cin>>a;
comp.insert(a);
x.push_back(a);
}
map<int,int> m;
int c=0;
for(auto &v:comp){
m[v]=c;
c++;
}
for(int i=1;i<=n;i++){
val[i]=m[x[i]];
}
cout<<report(0,-1)<<endl;
}
# | 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... |