Submission #1030351

#TimeUsernameProblemLanguageResultExecution timeMemory
1030351LuvidiGlobal Warming (CEOI18_glo)C++17
0 / 100
2061 ms6976 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back vector<int> lis(vector<int> a){ int n=a.size(); vector<int> ans(n),v; for(int i=0;i<n;i++){ if(v.empty()||v.back()<a[i])v.pb(a[i]); else{ int idx=lower_bound(v.begin(),v.end(),a[i])-v.begin(); v[idx]=a[i]; } ans[i]=v.size(); } return ans; } void solve() { int n,x; cin>>n>>x; vector<int> a(n); for(int i=0;i<n;i++)cin>>a[i]; vector<int> v1=lis(a),v2(n),a2(n); for(int i=0;i<n;i++)a2[i]=-a[n-1-i]; vector<int> t=lis(a2); for(int i=0;i<n;i++)v2[i]=t[n-1-i]; int ans=1; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++)if(a[i]-x<a[j]){ ans=max(ans,v1[i]+v2[j]); } } cout<<ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#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...