# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133847 | miguel | Global Warming (CEOI18_glo) | C++14 | 0 ms | 0 KiB |
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 rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define int ll
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
const ll nmax=5e4+2;
const ll mod = 998244353;
int n, x, s[200001], a[200001];
vector <int> dp;
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
cin>>n>>x;
//dp.pb(0);
for(int i=1; i<=n; i++){
cin>>a[i];
auto it=lower_bound(dp.begin(), dp.end(), a[i]);
if(it==dp.end()){
dp.pb(a[i]);
s[i]=dp.size();
}
else{
dp[it-dp.begin()]=a[i];
s[i]=it-dp.begin()+1;
}
}
// for(int i: dp) cout<<i<<" "; cout<<endl;
//for(int i=1; i<=n; i++) cout<<s[i]<<" ";
int ans=dp.size();
vi lsd;
for(int i=n; i>=1; --i){
auto it=lower_bound(lsd.begin(), lsd.end(), -a[i]);
if(it==lsd.end()) ans=max(ans, s[i]+lsd.size());
else ans=max(ans, s[i]+(it-lsd.begin()));
auto it1=lower_bound(lsd.begin(), lsd.end(), -a[i]-x);
if(it1==lsd.end()) lsd.pb(-a[i]-x);
else lsd[it1-lsd.begin()]=-a[i]-x;
}
cout<<ans;
}