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;
#define ll long long
const ll N = 3e5+5;
ll n,d,a[N],dp[N],mx[N];
//dp[i] = max dp[j] + 1 va (a[i] > a[j] && |i-j| <= D)
//OwO
signed main(){
cin>>n>>d;
for(ll i = 1;i <= n;++i) cin>>a[i];
// deque<ll>dq;
// for(ll i = 1;i <= n;++i){
// while(!dq.empty() && a[dq.back()] < a[i]) dq.pop_back();
// while(!dq.empty() && dq.front() + d <= i) dq.pop_front();
// dq.push_back(i);
// if(i <= d) mx[i] = a[dq.front()];
// }
dp[1] = 1;
for(ll i = 2;i <= n;++i){
dp[i] = 1;
for(ll j = 1;j < i;++j){
if(i - j <= d)
if(a[i] > a[j]) dp[i] = max(dp[i],dp[j] + 1);
}
// cerr<<"DEBUG: "<<i<<" "<<dp[i]<<endl;
}
ll res = 0;
for(ll i = 1;i <= n;++i) res = max(res,dp[i]);
cout<<res<<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... |