Cod sursa(job #1672795)

Utilizator anetAneta Anghel anet Data 3 aprilie 2016 08:09:27
Problema Subsir crescator maximal Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <cstdio>
#include <algorithm> 
using namespace std;

const int N = 100005;

int L, a[N], poz, p[N], s[N], v[N], n;
 
inline int Bs(int x)
{
    int l = 1, r = L, m;
	
    while (l <= r)
    {
        m = (l + r) / 2;
        if (v[m] < x) 
			l = m + 1;
        else 
			r = m - 1;
    }
    
    L = max(L, l);
    return l;
}

int main()
{
    freopen("scmax.in", "r", stdin);
    freopen("scmax.out", "w", stdout);
 
    scanf("%d", &n);
 
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d", &a[i]);
		p[i] = poz = Bs(a[i]);
        v[poz] = a[i];
    }
 
    printf("%d\n", L);
 
 
    for (int i = 1, j = 1; j <= L; ++i)
		if (p[i] == j) 
			s[j] = a[i], ++j;
 
    for (int i = 1; i <= L; ++i) 
		printf("%d ", s[i]);
    return 0;
}