Submission #918308

#TimeUsernameProblemLanguageResultExecution timeMemory
918308AiperiiiGlobal Warming (CEOI18_glo)C++14
100 / 100
92 ms10180 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n,x; cin>>n>>x; vector <int> a(n); for(int i=0;i<n;i++)cin>>a[i]; vector <int> v(n+1,1e18),v2(n+1,1e18); vector <int> l(n+1),r(n+1); v[0]=-1e18; v2[0]=-1e18; for(int i=0;i<n;i++){ auto pos=lower_bound(all(v),a[i])-v.begin(); l[i]=pos; v[pos]=a[i]; } for(int i=n-1;i>=0;i--){ auto pos=lower_bound(all(v2),-(a[i]-x))-v2.begin(); r[i]=pos; pos=lower_bound(all(v2),-a[i])-v2.begin(); v2[pos]=-a[i]; } int mx=0; for(int i=0;i<n;i++){ mx=max(mx,l[i]+r[i]-1); } cout<<mx<<"\n"; } /* 8 10 7 3 5 12 2 7 3 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...