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 long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=2e5+7;
ll n,m,k;
ll a[N];
ll dp[N];
int ri[N];
void precalc() {
}
int main() {
precalc();
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
ri[i]=i;
for(int j=i+1;j<min(n,ri[i]+k+1);j++){
if(a[j]<=a[i]){
ri[i]=j;
}
}
//cout<<ri[i]<<" ";
}
//cout<<endl;
ll ans=0;
for(int i=0;i<n;i++){
dp[i]=1;
for(int j=0;j<i;j++){
if(a[i]>a[j]&&ri[j]>=i-k){
dp[i]=max(dp[i],dp[j]+1);
}
}
if(ri[i]==n-1){
ans=max(ans,dp[i]);
}
//cout<<dp[i]<<" ";
}
cout<<ans<<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... |