Pagini recente » Cod sursa (job #1852482) | Cod sursa (job #779356)
Cod sursa(job #779356)
#include <fstream>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
int a[100000],best[100000],j,i,n,l,pbest,prec[100000],v[100000];
int main()
{
fin>>n;
for (i=1;i<=n;i++)
{
fin>>a[i];
best[i]=1;
for ( j=i-1;j>0;j--)
{
if (a[i]>a[j])
if(best[j]>=best[i])
{
best[i]=1+best[j];
prec[i]=j;
if ( best[i]>l)
{
pbest=i;
l=best[i];
}
}
}
}
fout<<best[pbest]<<"\n";
j=pbest;
for(i=1;i<=best[pbest];i++)
{
v[i]=a[j];
j=prec[j];
}
for(i=best[pbest];i>0;i--)
fout<<v[i]<<" ";
fout.close();
return 0;
}