Cod sursa(job #2538370)

Utilizator teisanumihai84Mihai Teisanu teisanumihai84 Data 4 februarie 2020 18:13:18
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#define DIM  100001
using namespace std;
int L[DIM], v[DIM], t[DIM], sol[DIM], n, i, st, dr, dim;
int main ()
{
    ifstream fin ("scmax.in");
    ofstream fout ("scmax.out");
    fin>>n;
    for (i=1; i<=n; i++)
        fin>>v[i];
    L[1]=1;
    dim=1;
    for (i=2; i<=n; i++)
    {
        st=1;
        dr=dim;
        while (st<=dr)
        {
            int mid=(st+dr)/2;
            if (v[L[mid]]>=v[i])
                dr=mid-1;
            else
                st=mid+1;
        }
        if (st>dim)
        {
            dim++;
            L[dim]=i;
            t[i]=L[dr];
        }
        else
        {
            L[st]=i;
            t[i]=L[dr];
        }
    }
    fout<<dim<<"\n";
    i=0;
    while (L[dim]!=0)
    {
        sol[++i]=v[L[dim]];
        L[dim]=t[L[dim]];
    }
    for (int j=i; j>=1; j--)
        fout<<sol[j]<<" ";
}