Cod sursa(job #3000280)

Utilizator rARES_4Popa Rares rARES_4 Data 12 martie 2023 11:34:04
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.08 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g ("scmax.out");
int n,l_sir;
int citit[100001],v[100001];
int poz[100001];
void cale(int x,int nr_de_cautat)
{
    if(nr_de_cautat ==0)
        return;
    for(int i = x;i>=0;i--)
    {
        if(poz[i] == nr_de_cautat)
        {
            cale(i-1,nr_de_cautat-1);
            g << citit[i]<< " ";
            return;
        }
    }
}
int cb(int x)
{
    int st = 1,dr = l_sir;
    int rasp = l_sir+1;
    while(st<=dr)
    {
        int mij = (st+dr)/2;
        if(v[mij]>=x)
        {
            dr = mij-1;
            rasp = mij;
        }
        else
            st = mij+1;

    }
    return rasp;
}
int main()
{
    f >> n;
    f >> citit[1];
    poz[1] = 1;
    v[1] = citit[1];
    l_sir = 1;
    for(int i = 2;i<=n;i++)
    {
        f >> citit[i];
        int poz_gasita = cb(citit[i]);
        v[poz_gasita] = citit[i];
        poz[i] = poz_gasita;
        l_sir = max(l_sir,poz_gasita);

    }
    g << l_sir<< "\n";
    cale(n,l_sir);
}