Cod sursa(job #1390667)

Utilizator Narcys01Ciovnicu Narcis Narcys01 Data 17 martie 2015 11:02:44
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <iostream>
#include <fstream>
#define N 100005

using namespace std;

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

int a[N], b[N], p[N], n;

inline int Best(int i, int x)
{
    int bst = 0, po = 0, j = i;
    for (i-- ; i > 0; i--)
        if (x > a[i] && b[i] > bst)
            bst = b[i],
            po = i;
    p[j] = po;
    return bst;
}

inline void Afis(int i)
{
    if (i == 0) return;
    Afis(p[i]);
    fout << a[i] << " ";
}

int main()
{
    int i, bb = 0, po = 0;
    fin >> n;
    for (i = 1; i <= n; i++)
        fin >> a[i];
    for (i = 1; i <= n; i++)
        b[i] = 1 + Best(i, a[i]);
    for (i = 1; i <= n; i++)
        if (bb < b[i])
            bb = b[i],
            po = i;
    fout << bb << "\n";
    Afis(p[po]);
    fout << a[po] << "\n";
    return 0;
}