Cod sursa(job #2324918)

Utilizator andreisavulescuSavulescu Andrei andreisavulescu Data 21 ianuarie 2019 18:44:43
Problema Subsir crescator maximal Scor 55
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <fstream>

using namespace std;

ifstream f("scmax.in");
ofstream g("scmax.out");
int vf[100001], nrs;

int CautBin(int x)
{
    int p = 1, u = nrs, poz = -1;
    while(p <= u)
    {
        int m = (p + u) / 2;
        if(x < vf[m])
        {
            poz = m;
            u = m - 1;
        }
        else
            p = m + 1;
    }
    return poz;
}

int main()
{
    int n, x;
    f >> n >> x;
    nrs = 1;
    vf[nrs] = x;
    for(int i = 2; i <= n; i++)
    {
        f >> x;
        if(x > vf[nrs])
            vf[++nrs] = x;
        else
        {
            int j = CautBin(x);
            vf[j] = x;
        }
    }
    g << nrs << '\n';
    for(int i = 1; i <= nrs; i++)
        g << vf[i] << ' ';
    return 0;
}