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 <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> a(n);
vector<int> lis, rlis;
vector<int> maxlis(n), rmaxlis(n);
vector<int> baselis(n), rbaselis(n);
for(int i = 0; i < n; i++){
cin >> a[i];
auto it = lower_bound(lis.begin(), lis.end(), a[i]);
auto it2 = lower_bound(lis.begin(), lis.end(), a[i] + x);
if(it == lis.end()){
lis.push_back(a[i]);
maxlis[i] = lis.size();
baselis[i] = lis.size();
}
else{
maxlis[i] = it2 - lis.begin();
baselis[i] = it - lis.begin();
*it = a[i];
}
}
for(int i = n - 1; i >= 0; i--){
auto it = lower_bound(rlis.begin(), rlis.end(), -a[i]);
auto it2 = lower_bound(rlis.begin(), rlis.end(), -a[i] - x);
if(it == rlis.end()){
rlis.push_back(-a[i]);
rmaxlis[i] = rlis.size();
rbaselis[i] = rlis.size();
}
else{
rmaxlis[i] = it2 - rlis.begin();
rbaselis[i] = it - rlis.begin();
*it = -a[i];
}
}
int maxi = 0;
for(int i = 0; i < n; i++){
maxi = max(maxi, max(maxlis[i] + rbaselis[i] - 1, baselis[i] + rmaxlis[i] - 1));
}
cout << maxi;
}
# | 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... |