Cod sursa(job #3313818)

Utilizator Cristian2010Baciu Cristian Cristian2010 Data 6 octombrie 2025 21:52:07
Problema Subsir crescator maximal Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int main()
{
int N, i, max, last, j;
fin >> N;
int v[100005], D[100005], prev[100005];
for (i=1; i<=N; i++)
{
    fin >> v[i];
    D[i]=1;
    prev[i]=0;
}
max=1;
last = 1;
for (i=1; i<=N; i++)
{
    for (j=1; j<i; j++)
    {
        if (v[j]<v[i] && D[j]+1 > D[i])
        {
            D[i]=D[j]+1;
            prev[i]=j;
        }
    }
    if (D[i]>max)
    {
        max=D[i];
        last=i;
    }
}
fout << max << "\n";
int seq[100005], len;
len=0;
while (last != 0)
{
    seq[len++]=v[last];
    last=prev[last];
}
for (i=len-1; i>=0; i--)
{
        fout << seq[i] << " ";
}
fout << "\n";
return 0;
}