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;
#define all(x) x.begin(),x.end()
const int N = 3e5 + 10, INF = 2e9 + 10;
int n, x, a[N], l[N], ans;
vector <int> v(N, INF);
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> x;
for (int i = 0; i < n; ++ i){
cin >> a[i];
}
v[0] = -INF;
for (int i = 0; i < n; ++ i){
int p = lower_bound (all(v), a[i]) - v.begin();
v[p] = a[i];
l[i] = p;
ans = max (ans, p);
}
for (int i = 0; i < n; ++ i){
v[i] = INF;
}
v[0] = -INF;
for (int i = n - 1; i >= 0; -- i){
int p = lower_bound (all(v), -a[i] + x) - v.begin();
ans = max (ans, l[i] + p - 1);
p = lower_bound (all(v), -a[i]) - v.begin();
v[p] = -a[i];
}
cout << ans;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |