Pagini recente » Cod sursa (job #2100915) | Cod sursa (job #2167494) | Cod sursa (job #3266517) | Cod sursa (job #378121) | Cod sursa (job #2313850)
#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], prec[100005], rasp[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, l = 0, jret = 0;
for (int j = i - 1; j >= 1; j--)
if (v[j] < v[i] && mare < d[j])
{
mare = d[j];
prec[i] = j;
}
d[i] = mare + 1;
if (d[i] > lmax)
{
lmax = d[i];
imax = i;
}
}
Fout << lmax << '\n';
int k = 0;
for (int i = imax; i >= 1; i = prec[i])
rasp[++k] = v[i];
for (int i = k; i >= 1; i--)
fout << rasp[i] << ' ';
fout << '\n';
return 0;
}