Cod sursa(job #2333881)

Utilizator PetrescuAlexandru Petrescu Petrescu Data 2 februarie 2019 01:38:24
Problema Subsir crescator maximal Scor 45
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <fstream>
#include <iostream>
#define MAX 100001

using namespace std;

int v[MAX], T[MAX];
int main()
{
    int n, i, j,st, dr, mij, length = 0, gasit;

    ifstream fin("scmax.in");
    ofstream fout("scmax.out");

    fin >> n;

    for(i = 1; i <= n; i++)
        fin >> v[i];

    length = 1;
    T[1] = 1;
    for(i = 2; i <= n; i++)
    {
        st = 1;
        dr = length;

        gasit = -1;
        while(st <= dr)
        {
            mij = (st + dr) / 2;

            if(v[i] < v[T[mij]])
            {
                gasit = mij;
                dr = mij - 1;
            }
            else st = mij + 1;
        }

        if(gasit == -1)
        {
            length++;
            T[length] = i;
        }
        else T[gasit] = i;

    }

    //for(i = 1; i <= length; i++)cout << T[i] << " ";
    fout << length;

    fin.close();
    fout.close();

    return 0;
}