#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define FOR1(a) for (int _ = 1; _ <= (a); _++)
#define FOR2(i, a) for (int i = 1; i <= (a); i++)
#define FOR3(i, a, b) for (int i = (a); i <= (b); i++)
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload3(__VA_ARGS__, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define sep ' '
#define endl '\n'
#define print(a) cerr << #a << " = " << a << endl;
#define X first
#define Y second
#define MP make_pair
#define MT make_tuple
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin());
#define LC (v << 1)
#define RC (LC | 1)
#define mid ((l+r) / 2)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 7000 + 4;
const int INF = 1ll << 60;
int n, d;
int a[N];
int mx[N], dp[N];
void SOLVE() {
cin >> n >> d;
FOR(i, n) cin >> a[i];
FOR(i, n) {
FOR(j, 1, i-1) if (i - mx[j] <= d) {
if (a[i] <= a[j]) mx[j] = i;
else chmax(dp[i], dp[j] + 1);
}
mx[i] = i;
chmax(dp[i], 1ll);
}
// cout << "mx: "; FOR(i, n) cout << mx[i] << "\t";
// cout << endl;
// cout << "dp: "; FOR(i, n) cout << dp[i] << "\t";
cout << *max_element(dp+1, dp+n+1);
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int T = 1;
// cin >> T;
FOR(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... |