Cod sursa(job #1279900)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 1 decembrie 2014 01:03:47
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <fstream>
#include <iostream>

using namespace std;

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

const int NMax = 100003;
int v[NMax],best[NMax];

int main()
{
    int n,poz = 1,lmax = 1;
    f >> n;
    for(int i = 1; i <= n; i++)
        f >> v[i];
    best[n] = 1;
    for(int i = n - 1; i > 0; i--){
        best[i] = 1;
        for(int j = i + 1; j <= n; j++){
            if(v[i] < v[j] && best[i] < best[j] + 1){
                best[i] = best[j] + 1;
                if(best[i] > lmax)
                    lmax = best[i];
                    poz = i;
            }
        }
    }
    g << lmax << "\n";
    for(int i = poz; i <= n && lmax != 0; i++){
        if(best[i] == lmax){
            g << v[i] << " ";
            lmax--;
        }
    }
    return 0;
}