Cod sursa(job #1877182)

Utilizator bt.panteaPantea Beniamin bt.pantea Data 13 februarie 2017 08:28:46
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <fstream>
#define NMAX 100010
using namespace std;
ifstream f ("scmax.in");
ofstream g ("scmax.out");
int best[NMAX], v[NMAX], pre[NMAX], MAX, poz, n;

void Write(int x)
{
    if (pre[x] != -1)
        Write(pre[x]);
    g<<v[x]<<' ';
}

int main()
{
    f >> n;
    for (int i = 0; i < n; i++)
    {
        f>>v[i];
        int bestPoz = -1, Max = 0;
        for (int j = 0; j < i; j++)
        {
            if (v[j] < v[i] && Max < best[j])
                Max = best[j], bestPoz = j;
        }
        best[i] = Max + 1;
        pre[i] = bestPoz;
        if (best[i] > MAX)
            MAX = best[i], poz = i;
    }
    g<<MAX<<'\n';
    Write(poz);
    return 0;
}