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>
#define ll long long
#define MAXN 200010
using namespace std;
ll t[MAXN],lis[MAXN];
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,x,ans=0;
cin >> n >> x;
for (ll i=1;i<=n;i++)
cin >> t[i];
vector<ll> v;
for (ll i=1;i<=n;i++)
{
auto it=lower_bound(v.begin(),v.end(),t[i]);
if (it==v.end())
{
v.push_back(t[i]);
lis[i]=v.size();
}
else
{
lis[i]=it-v.begin()+1;
v[it-v.begin()]=t[i];
}
}
v.clear();
for (ll i=n;i>0;i--)
{
auto it=lower_bound(v.begin(),v.end(),-t[i]);
ans=max(ans,lis[i]+(it-v.begin()));
t[i]+=x;
it=lower_bound(v.begin(),v.end(),-t[i]);
if (it==v.end())
v.push_back(-t[i]);
else
v[it-v.begin()]=-t[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... |