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>
#include <iostream>
using namespace std;
#define ll long long int
const ll inf = 4e18;
int main()
{
ll N,X;
cin>>N>>X;
vector<ll> a(N+10);
vector<ll> b(N+10);
for (int i=1;i<=N;i++) {
cin>>a[i];
b[N+1-i] = -a[i];
}
vector<ll> l1(N+10, inf);
vector<ll> ll1(N+10,inf);
l1[0] = -inf;
for (int i=1;i<=N;i++) {
int l = lower_bound(l1.begin()+1, l1.end(), a[i]) - (l1.begin());
if (l1[l-1] < a[i] && a[i] < l1[l]) {
l1[l] = a[i];
}
ll1[i] = l;
}
vector<ll> l2(N+10, inf);
vector<ll> ll2(N+10,inf);
l2[0] = -inf;
for (int i=1;i<=N;i++) {
int tt = lower_bound(l2.begin()+1, l2.end(), (b[i]+X)) - l2.begin();
int l = lower_bound(l2.begin()+1, l2.end(), b[i]) - (l2.begin());
if (l2[l-1] < b[i] && b[i] < l2[l]) {
l2[l] = b[i];
}
ll2[N+1-i] = tt-1;
}
ll ans = 1;
for (int i=1;i<N;i++) {
ans = max(ll1[i]+ll2[i], ans);
}
cout << ans;
return 0;
}
/*
8 10
7 3 5 12 2 7 3 4
*/
# | 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... |