Cod sursa(job #2489901)

Utilizator iulianarsenoiuArsenoiu Iulian iulianarsenoiu Data 9 noiembrie 2019 13:01:58
Problema Subsir crescator maximal Scor 15
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>
#include <algorithm>
#include <stack>

using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int n,x,i,l[100005],nr,poz,prc[100005];
stack <int> st;
int main()
{
    f>>n;
    f>>x;
    l[1]=x;
    for(i=2;i<=n;i++)
    {
        f>>x;
        poz=lower_bound(l+1,l+nr+1,x)-l;
        l[poz]=x;
        prc[x]=l[poz-1];
        if(poz>nr)
            nr=poz;
    }
    g<<nr<<'\n';
    x=l[nr];
    st.push(x);
    while(prc[x]!=0)
    {
        x=prc[x];
        st.push(x);
    }
    while(!st.empty())
    {
        g<<st.top()<<' ';
        st.pop();
    }
    g<<'\n';
    return 0;
}