Pagini recente » Cod sursa (job #2444667) | Cod sursa (job #119066) | Cod sursa (job #828583) | Cod sursa (job #3171866) | Cod sursa (job #2964262)
#include <fstream>
using namespace std;
const int N = 100000;
int v[N + 1];
int lung[N + 1];
void afis_subsir(int p, int lmax, ofstream &out)
{
if (p == 0)
{
return;
}
if (lung[p] != lmax - 1)
{
afis_subsir(p - 1, lmax, out);
}
else
{
afis_subsir(p - 1, lung[p], out);
out << v[p] << ' ';
}
}
int main()
{
ifstream in("scmax.in");
ofstream out("scmax.out");
int n;
in >> n;
int pmax = 1;
for (int i = 1; i <= n; i ++)
{
in >> v[i];
int lmax = 0;
for (int j = 1; j < i; j ++)
{
if (v[j] < v[i])
{
lmax = max(lmax, lung[j]);
}
}
lung[i] = lmax + 1;
if (lung[i] > lung[pmax])
{
pmax = i;
}
}
out << lung[pmax] << '\n';
afis_subsir(pmax, lung[pmax], out);
out << v[pmax] << ' ';
in.close();
out.close();
return 0;
}