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;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, x;
cin >> n >> x;
vector<int> a(n);
for (auto &i : a)
cin >> i;
deque<int> v;
vector<int> u(n);
for (int i = n - 1; i >= 0; i--) {
if (v.empty() || v[0] > a[i]) {
v.push_front(a[i]);
u[i] = (int)v.size();
}
else {
int t = upper_bound(v.begin(), v.end(), a[i]) - v.begin() - 1;
u[i] = (int)v.size() - t; v[t] = a[i];
}
}
v.clear();
int ans = u[0];
for (int i = 0; i < n; i++) {
if (v.empty() || v.back() < a[i]) {
ans = max(ans, (int)v.size() + u[i]);
v.push_back(a[i]);
}
else {
ans = max(ans, (int)(lower_bound(v.begin(), v.end(), a[i] + x) - v.begin()) + u[i]);
v[lower_bound(v.begin(), v.end(), a[i]) - v.begin()] = a[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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |