Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include<fstream>
  2. using namespace std;
  3. ifstream cin("sclm2.in");
  4. ofstream cout("sclm2.out");
  5. int v[100005],L[100005],best[100005],n,poz,maxim,nr;
  6. int caut(int x)
  7. {
  8. int p=0,u=nr,m;
  9. m=(p+u)/2;
  10. while(p<=u)
  11. {
  12. if(v[L[m]]<x && v[L[m+1]]>=x) return m;
  13. else if(v[L[m+1]]<x) {p=m+1; m=(p+u)/2;}
  14. else {u=m-1; m=(p+u)/2;}
  15. }
  16. return nr;
  17. }
  18. int main()
  19. {
  20. cin>>n;
  21. for(int i=1;i<=n;i++) cin>>v[i];
  22. cin.close();
  23. nr=1; best[1]=L[1]=1;
  24. for(int i=2;i<=n;i++)
  25. {
  26. poz=caut(v[i]);
  27. best[i]=poz+1;
  28. L[poz+1]=i;
  29. if(nr<poz+1) nr=poz+1;
  30. }
  31. for(int i=1;i<=n;i++)
  32. if(maxim<best[i])
  33. maxim=best[i];
  34. cout<<maxim<<'\n';
  35. cout.close();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement