Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define DIM 100005
- int a[DIM], lung[DIM], best[DIM];
- int n, max, poz;
- void read()
- {
- int i;
- scanf("%d", &n);
- for (i = 1; i <= n; ++i)
- scanf("%d", &a[i]);
- }
- int cbin(int st, int dr, int x)
- {
- int mij;
- for (; st <= dr; )
- {
- mij = (st + dr) / 2;
- if (a[lung[mij]] <= a[x] && (a[lung[mij + 1]] > a[x] || mij + 1 > max))
- return mij;
- else if (a[lung[mij]] <= a[x])
- st = mij + 1;
- else
- dr = mij - 1;
- }
- return 0;
- }
- void solve()
- {
- int i, j;
- for (i = 1; i <= n; ++i)
- {
- j = cbin(1, max, i);
- if (j == max || a[i] <= a[lung[j + 1]])
- {
- lung[j + 1] = i;
- best[i] = j + 1;
- if (j + 1 > max) max = j + 1;
- }
- }
- printf("%d\n", max);
- }
- int main()
- {
- freopen("date.txt", "r", stdin);
- freopen("scmax.out", "w", stdout);
- read();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment