Pagini recente » Cod sursa (job #2254871) | Cod sursa (job #688510) | Cod sursa (job #904841) | Cod sursa (job #2691733) | Cod sursa (job #1961534)
#include <iostream>
#include <fstream>
using namespace std;
int a[100010], l[100010], t[100010], b[100010];
int main()
{
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
int n, i, j, max, x=0;
fin >> n;
for (i=1; i<=n; i++)
{
fin >> a[i];
max=i;
for (j=i-1; j>=1; j--)
if (l[j]>l[max] && a[j]<a[i])
max=j;
l[i]=l[max]+1;
if (max==i)
t[i]=0;
else
t[i]=max;
}
max=1;
for (i=1; i<=n; i++)
{
if (l[i]>l[max])
max=i;
}
fout << l[max] << "\n";
while (t[max])
{
b[++x]=a[max];
max=t[max];
}
b[++x]=a[max];
for (i=x; i>=1; i--)
fout << b[i] << " ";
return 0;
}