Pagini recente » Cod sursa (job #3041309) | Cod sursa (job #406378) | Cod sursa (job #387322) | Cod sursa (job #1205507) | Cod sursa (job #2044910)
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int a[100001],l[100001],t[100001],n,i,v,j,pmax,vfc;
int main()
{
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
for(i=n;i>=1;i--)
{
v=0;
t[i]=0;
for(j=i+1;j<=n;j++)
{
if(a[i]<a[j]&&l[j]>v)
{
v=l[j];
t[i]=j;
}
l[i]=v+1;
}
}
pmax=1;
for (int i=2;i<=n;i++)
if (l[i]>l[pmax])
pmax=i;
g<<l[pmax]<<'\n';
vfc=pmax;
while (vfc!=0)
{
g<<a[vfc]<<" ";
vfc=t[vfc];
}
return 0;
}