Cod sursa(job #2313784)

Utilizator IoanaDraganescuIoana Draganescu IoanaDraganescu Data 7 ianuarie 2019 14:27:24
Problema Subsir crescator maximal Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <climits>

using namespace std;

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

int v[100005], d[100005];

int main()
{
    int n, lmax = 0, imax = 0;
    fin >> n;
    for (int i = 1; i <= n; i++)
        fin >> v[i];
    d[1] = 1;
    for (int i = 1; i <= n; i++)
    {
        int mare = 0;
        for (int j = i - 1; j >= 1; j--)
            if (v[j] < v[i] && mare < d[j])
                mare = d[j];
        d[i] = mare + 1;
        if (d[i] > lmax)
        {
            lmax = d[i];
            imax = i;
        }
    }
    fout << lmax << '\n';
    for (int i = 1; i <= imax; i++)
        if (v[i] <= v[imax] && v[i] != v[i - 1])
            fout << v[i] << ' ';
    fout << '\n';
    return 0;
}