Cod sursa(job #2397642)

Utilizator AndreiStrAndrei Stroici AndreiStr Data 4 aprilie 2019 17:34:13
Problema Subsir crescator maximal Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
const int N=100001;
int n,a[N],b[N],p[N],v[N],lo,hi,mi,lmax;
void print(int);
int main()
{
    f>>n;
    for(int i=1;i<=n;i++)
    {
        f>>a[i];
        lo=0;
        hi=lmax+1;
        while(hi-lo>1)
        {
            mi=(lo+hi)/2;
            if(v[mi]<a[i])
                lo=mi;
            else
                hi=mi;
        }
        v[hi]=a[i];
        p[hi]=i;
        b[hi]=p[lo];
        if(hi>lmax)
            lmax++;
    }
    g<<lmax<<'\n';
    print(p[lmax]);
    return 0;
}
void print(int i)
{
    if(i==0)
        return;
    print(b[i]);
    g<<a[i]<<' ';
}