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;
int pre[200100], suf[200100], arr[200100], ans;
vector<int> v;
int main() {
int n, x;
cin >> n >> x;
for(int i = 0; i < n; i++) {
cin >> arr[i];
auto it = lower_bound(v.begin(), v.end(), arr[i]);
pre[i] = it-v.begin()+1;
if(it==v.end())
v.push_back(arr[i]);
else *it = arr[i];
}
v.clear();
for(int i = n; i--;) {
auto it = lower_bound(v.begin(), v.end(), arr[i], [](int a, int b){return a>b;});
auto i2 = lower_bound(v.begin(), v.end(), arr[i] - x, [](int a, int b){return a>b;});
suf[i] = i2-v.begin()+1;
if(it==v.end())
v.push_back(arr[i]);
else *it = arr[i];
}
for(int i = 0; i < n; i++){
ans = max(ans, pre[i]+suf[i]-1);
}
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... |