Cod sursa(job #2672599)

Utilizator sorana5Gligor Sorana sorana5 Data 14 noiembrie 2020 11:35:30
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream f("scmax.in");
ofstream g("scmax.out");

vector <int> seq[100005];

int n, x, lmax;

int binar (int poz1, int poz2, int nr)
{
    while (poz2 > poz1)
    {
        int mid = (poz2 + poz1) / 2;
        if (seq[mid][mid] >= nr)
            poz2 = mid;
        else
            poz1 = mid + 1;
    }
    return poz2;
}

int main()
{
    f>>n;
    f>>x;
    seq[0].push_back(x);
    lmax = 1;
    for (int i = 2 ; i <= n; ++i)
    {
        f>>x;
        int index = binar(0, lmax, x);
        if (index == 0)
        {
            seq[0][0] = x;
            continue;
        }
        if (index == lmax)
            lmax++;
        seq[index].clear();
        for (int j = 0; j < index; ++j)
            seq[index].push_back(seq[index-1][j]);
        seq[index].push_back(x);
    }
    g<<lmax<<'\n';
    for (int i = 0; i < lmax; ++i)
        g<<seq[lmax-1][i]<<' ';

    f.close();
    g.close();
    return 0;
}