Submission #260506

#TimeUsernameProblemLanguageResultExecution timeMemory
260506stefantagaGlobal Warming (CEOI18_glo)C++14
0 / 100
2074 ms4948 KiB
#include <bits/stdc++.h> using namespace std; int n,x,i,v[200005],b[200005],poz,lcresc[200005],ldesc[200005],j,maxim; int caut (int val) { int st=1,dr=n,mij,sol=0; while (st<=dr) { mij=(st+dr)/2; if (b[mij]<=val) { sol=mij; st=mij+1; } else { dr=mij-1; } } return sol; } int caut1 (int val) { int st=1,dr=n,mij,sol=0; while (st<=dr) { mij=(st+dr)/2; if (b[mij]>=val) { dr=mij-1; } else { sol=mij; st=mij+1; } } return sol; } int main() { #ifdef HOME ifstream cin("date.in"); ofstream cout("date.out"); #endif // HOME cin>>n>>x; for (i=1;i<=n;i++) { b[i]=2000000005; } for (i=1;i<=n;i++) { cin>>v[i]; poz=caut(v[i]); if (v[i]<b[poz+1]) { b[poz+1]=v[i]; lcresc[i]=poz+1; } } for (i=1;i<=n;i++) { b[i]=-2000000005; } for (i=n;i>=1;i--) { ldesc[i]=1; for (j=i+1;j<=n;j++) { if (v[i]<v[j]) { ldesc[i]=max(ldesc[i],ldesc[j]+1); } } } maxim=1; for (i=1;i<=n;i++) { for (j=i-1;j>=1;j--) { if (v[j]-x<v[i]) { maxim=max(maxim,ldesc[i]+lcresc[j]); } } } cout<<maxim; return 0; }
#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...