Cod sursa(job #2150174)

Utilizator PredaBossPreda Andrei PredaBoss Data 3 martie 2018 12:28:05
Problema Subsir crescator maximal Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 1.21 kb
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int sir[100002],n,i,j,k,lmax;
vector<int>seq[100002];
int binar(int pos1,int pos2,int x)
{
    while(pos2-pos1>1)
    {
        int mid=(pos1+pos2)/2;
        if(seq[mid][mid-1]<=x)
            pos1=mid;
        else
            pos2=mid;
    }
    return pos2;
}
int putsir(int x)
{
    if(lmax==0)
    {
        seq[1].pb(x);
        lmax=1;
    }
    else
    {
        j=0;
        j=binar(0,lmax+1,x);
        if(j!=lmax+1)
        {
        seq[j][j-1]=x;
        for(int g=0;g<j-1;g++)
            seq[j][g]=seq[j-1][g];
        }
        else
        {
            if(x!=seq[lmax][lmax-1])
            {
            lmax++;
            for(int g=0;g<lmax;g++)
                seq[lmax].pb(seq[lmax-1][g]);
            seq[lmax][lmax-1]=x;
            }
        }
    }

}
void rez()
{
    for(i=1;i<=n;i++)
    {
        putsir(sir[i]);
    }
        fout<<lmax<<"\n";
        for(i=0;i<lmax;i++)
            fout<<seq[lmax][i]<<" ";
}
int main()
{
    fin>>n;
    lmax=0;
    for(i=1;i<=n;i++)
        fin>>sir[i];
    rez();
    return 0;
}