Cod sursa(job #2796731)

Utilizator Casian_doispeChiriac Casian Casian_doispe Data 8 noiembrie 2021 19:02:04
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.01 kb
#include <fstream>
#include <cstring>
#include <vector>

using namespace std;

ifstream cin("scmax.in");
ofstream cout("scmax.out");

vector<int> rez, aux ;

int v[100009], pozaux[100009] ;

void afis(int f, int n)
{

    while(n > 0)
    {

        ///cout << pozaux[n] << " " << f << endl ;

        if(pozaux[n] == f)
            rez.push_back(v[n]), f -- ;

        n -- ;
    }

    for(int f = rez.size() - 1 ; f >= 0 ; f --)
        cout << rez[f] << " " ;
}

int main()
{
    int n ;

    cin >> n ;

    for(int f = 1 ; f <= n ; f ++)
        cin >> v[f] ;

    for(int f = 1 ; f <= n ; f ++)
        if(!aux.size() || v[f] > aux.back())
            aux.push_back(v[f]), pozaux[f] = aux.size() - 1 ;
        else
        {
            int poz = (int)(lower_bound(aux.begin(), aux.end(), v[f]) - aux.begin()) ;

            aux[poz] = v[f] ;

            pozaux[f] = poz ;
        }

    cout << aux.size() << endl ;

    afis(aux.size() - 1, n) ;

    return 0;
}