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;
int dp[300010];
int n, d;
int a[300010];
int solve(int i) {
if(i==n) {
return 1;
}
int &ret = dp[i];
if(ret != -1){
return ret;
}
ret = 0;
int last = i;
for(int j=i+1; j-last<=d && j<=n; ++j) {
if(a[j]<=a[i]){
last = j;
}
else {
ret = max(ret, solve(j));
}
}
ret++;
return ret;
}
int main(){
cin>>n>>d;
for(int i=1; i<=n; ++i) {
cin>>a[i];
}
memset(dp, -1, sizeof dp);
int ans = 0;
for(int i=1; i<=n; ++i) {
ans = max(ans, solve(i));
}
cout<<ans;
}
# | 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... |