Cod sursa(job #2387309)

Utilizator cristian51090Oanta Cristian cristian51090 Data 24 martie 2019 14:58:53
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
const int N=2e5;
int v[N],p[N],q[N];
int i,j,n,Q,aux;

int a(int elemq,int poz)
{
    while(p[poz]!=elemq)
        poz--;
    if(elemq>1)
        a(elemq-1,poz-1);
    g<<v[poz]<<" ";
}

int main()
{
    f>>n;
    for(i=1; i<=n; i++)
    {
        f>>v[i];
        aux=v[i];
        j=1;
        while(aux>q[j]&&j<=Q)
            j++;
        q[j]=aux;
        p[i]=j;
        Q=max(Q,j);
    }

    g<<Q<<"\n";
    a(Q,n);
    return 0;
}