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 pb push_back
#define fr first
#define sc second
int arr[200001];
int n, x;
vector <int> sup;
int dp[200001];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin>>n>>x;
for (int i=0; i<n; i++)
{
cin>>arr[i];
}
for (int i=0; i<n; i++)
{
auto it = lower_bound(sup.begin(), sup.end(), arr[i]);
if (it == sup.end())
{
sup.pb(arr[i]);
dp[i] = sup.size();
continue;
}
int pos = it - sup.begin();
dp[i] = pos + 1;
sup[pos] = arr[i];
}
sup.clear();
int mx = 0;
for (int i=n-1; i>=0; i--)
{
auto it = lower_bound(sup.begin(), sup.end(), -(arr[i]-x));
int val = (it-sup.begin());
val += dp[i];
mx = max(val, mx);
it = lower_bound(sup.begin(), sup.end(), -(arr[i]));
if (it == sup.end())
{
sup.pb(-arr[i]);
continue;
}
int pos = it - sup.begin();
sup[pos] = -arr[i];
}
cout<<mx;
}
# | 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... |