Pagini recente » Cod sursa (job #945458) | Cod sursa (job #1439287) | Cod sursa (job #892111) | Cod sursa (job #2348510) | Cod sursa (job #1013256)
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream f("scmax.in");
ofstream g("scmax.out");
long n,i,j,max,max2,a[100001],l[100001],p[100001],poz;
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
max2=n;
l[n]=1;
p[n]=0;
for (i=n-1; i>=1; i--)
{
poz=0;
max=0;
for (j=i+1; j<=n; j++)
if (a[i]<a[j] && l[j]>max)
{
max=l[j];
poz=j;
}
l[i]=1+max;
p[i]=poz;
if (l[i]>l[max2])
max2=i;
}
g<<l[max2]<<'\n';
while(max2>0)
{
g<<a[max2]<<" ";
max2=p[max2];
}
f.close();
g.close();
return 0;
}