Cod sursa(job #1706825)

Utilizator mihai9xxMihai9 mihai9xx Data 23 mai 2016 14:53:38
Problema Subsir crescator maximal Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int v[100005],p[100005],q[100005];
int i,j,n,mx,x;
void xddd(int fx, int fp){
    while (p[fp]!=fx)
        fp--;
    if (fx>1)
        xddd(fx-1,fp-1);
    g<<v[fp]<<" ";
}
int main(){
    f>>n;
    for (i=1;i<=n;i++){
        f>>v[i];
        x=v[i];
        j=1;
        while (x>q[j] && j<=mx)
            j++;
            q[j]=x;
        p[i]=j;
        mx=max(mx,j);
    }
    g<<mx<<"\n";
    xddd(mx,n);
}