Alx09

Untitled

Apr 16th, 2020
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #define DIM 100005
  3. int a[DIM], lung[DIM], best[DIM];
  4. int n, max, poz;
  5. void read()
  6. {
  7. int i;
  8. scanf("%d", &n);
  9. for (i = 1; i <= n; ++i)
  10. scanf("%d", &a[i]);
  11. }
  12.  
  13. int cbin(int st, int dr, int x)
  14. {
  15. int mij;
  16. for (; st <= dr; )
  17. {
  18. mij = (st + dr) / 2;
  19. if (a[lung[mij]] <= a[x] && (a[lung[mij + 1]] > a[x] || mij + 1 > max))
  20. return mij;
  21. else if (a[lung[mij]] <= a[x])
  22. st = mij + 1;
  23. else
  24. dr = mij - 1;
  25. }
  26. return 0;
  27. }
  28. void solve()
  29. {
  30. int i, j;
  31. for (i = 1; i <= n; ++i)
  32. {
  33. j = cbin(1, max, i);
  34. if (j == max || a[i] <= a[lung[j + 1]])
  35. {
  36. lung[j + 1] = i;
  37. best[i] = j + 1;
  38. if (j + 1 > max) max = j + 1;
  39. }
  40. }
  41. printf("%d\n", max);
  42.  
  43. }
  44. int main()
  45. {
  46. freopen("date.txt", "r", stdin);
  47. freopen("scmax.out", "w", stdout);
  48. read();
  49. solve();
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment