Cod sursa(job #751267)

Utilizator andreipasalauPasalau Andrei andreipasalau Data 25 mai 2012 09:30:46
Problema Subsir crescator maximal Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#include <algorithm>
#include <fstream>

using namespace std;

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

#define DIM 100005
#define DIM 100005

int v[DIM],bst[DIM],t[DIM];
int n,sol,ind;

void read ()
{
 
}

int cbin (int val)
{
    int st, dr, mij;

    for (st = 0, dr = sol; st <= dr; )
    {
        mij = (st + dr) / 2;
        if (mij == dr || (v[bst[mij]] < val && v[bst[mij+1]] >= val))
            return mij;
        else if (v[bst[mij]] < val)
            st = mij + 1;
        else
            dr = mij - 1;
    }
    return 0;
}

void print (int poz)
{
    if (t[poz])
        print (t[poz]);
	g << v[poz] << " ";
}

void solve ()
{
    int i, poz;
    bst[1] = 1;
    for (i = 2; i <= n; i++)
    {
        poz = cbin(v[i]);
        t[i] = bst[poz];
        bst[poz + 1] = i;
        if (poz + 1 > sol)
        {
            sol = poz + 1;
            ind = i;
        }
    }
	g << sol << '\n';
    print(ind);
}

int main ()
{
	int i;
	f >> n;
    for (i = 1; i <= n; i++)
       f >> v[i];
    sol = 1;
	ind = 1;
    solve ();

    return 0;
}