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 main(){
int n,d;
cin>>n>>d;
vector<int> v(n);
for(int& a : v) cin>>a;
vector<int> smallest(n+1, 1e9+7), here(n);
smallest[0] = 0;
for(int i = 0; i < n; i++){
int l = lower_bound(smallest.begin(), smallest.end(), v[i]) - smallest.begin();
here[i] = l;
smallest[l] = v[i];
}
vector<int> biggest(n+1, -(1e9+7));
biggest[0] = 1e9+7;
int sol = 0;
for(int i = n-1; i >= 0; i--){
int l = 0, r = n;
while(r-l > 1)
if(biggest[(r+l)/2] > v[i]-d) l = (l+r)/2;
else r = (l+r)/2;
sol = max(sol, l+here[i]);
l = 0, r = n;
while(r-l > 1)
if(biggest[(r+l)/2] > v[i]) l = (l+r)/2;
else r = (l+r)/2;
biggest[l+1] = v[i];
}
cout << sol << "\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... |