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;
constexpr int inf = 1e9 + 7;
void solve() {
int n, d;
cin >> n >> d;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<pair<int, int>> lr(n);
for (int i = 0; i < n; ++i) {
lr[i] = {i, i};
int prv = i;
for (int j = i - 1; j >= 0; --j) {
if (a[j] < a[i]) {
prv = j;
}
if (prv - j >= d) {
break;
}
lr[i].first = j;
}
}
vector<pair<int, int>> ord(n);
for (int i = 0; i < n; ++i) {
ord[i] = {a[i], -i};
}
sort(ord.begin(), ord.end());
vector<int> dp(n, -inf);
int ans = 0;
for (auto [vl, pos] : ord) {
int i = -pos;
dp[i] = 1;
for (int j = lr[i].first; j < lr[i].second; ++j) {
dp[i] = max(dp[i], dp[j] + 1);
}
ans = max(ans, dp[i]);
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
# | 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... |