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 A[500005], dp[300005];
map<pair<int, int> , int> m;
int n,d;
int c(int i, int mx){
if(i >= n)return 0;
if(m[{i,mx}])return m[{i,mx}];
int ans = 0;
for(int j=i+1;j<=min(i+d, n);j++){
ans = max(ans, c(j, max(mx,A[j])) + (A[j]>mx?1:0));
}
//cout << i << " " << mx << " " << ans << '\n';
if(mx == -1)ans = max(ans, c(i+1, -1));
return m[{i,mx}] = ans;
}
int main(){
cin >> n >> d;
for(int i=1;i<=n;i++)cin >> A[i];
cout << c(0, -1) << '\n';
}
# | 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... |