#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
const int N = 3e5 + 7, M = 5e6 + 7, mod = 1e9 + 7;
int n, d, a[N], dp[N];
void solve() {
cin>>n>>d;
for(int i = 1; i <= n; i++) {
cin>>a[i];
dp[i] = 1;
}
int mx = 0;
for(int i = 1; i <= n; i++) {
for(int j = i + 1; j <= n; j++) {
if(a[j] > a[i]) {
int last = i;
bool ok = 1;
for(int k = i + 1; k <= j; k++) {
if(a[k] <= a[i])last = k;
else {
if(k - last > d) {
ok = 0;
break;
}
}
}
if(ok)dp[j] = max(dp[j], dp[i] + 1);
}
}
// cout << i << ' ' << dp[i] << '\n';
mx = max(mx, dp[i]);
}
cout << mx << '\n';
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
int T = 1;
// cin>>T;
while(T --)solve();
}
| # | 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... |