Pagini recente » Cod sursa (job #406449) | Cod sursa (job #2074232) | Cod sursa (job #707925) | Cod sursa (job #1586590) | Cod sursa (job #2313784)
#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;
}