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;
using ll = long long;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr ll INFLL = numeric_limits<ll>::max() / 2;
template<class T>
istream &operator>>(istream &is, vector<T> &a) {
for (auto &i : a) {
is >> i;
}
return is;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
#endif
int n, d;
cin >> n >> d;
vector<int> a(n);
cin >> a;
vector<int> dp(n), ri(n);
for (int i = 0; i < n; ++i) {
dp[i] = 1;
ri[i] = i;
for (int j = 0; j < i; ++j) {
if (i - ri[j] <= d && a[j] < a[i]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
for (int j = 0; j <= i; ++j) {
if (i - ri[j] <= d && a[i] <= a[j]) {
ri[j] = i;
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
if (ri[i] == n - 1) {
ans = max(ans, dp[i]);
}
}
cout << ans << "\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... |