Pagini recente » Profil EZY_PETRU124 | Rating Ghita Alexandru (Ghitzarino) | Cod sursa (job #2613249) | Cod sursa (job #693079)
Cod sursa(job #693079)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in ("scmax.in");
ofstream out("scmax.out");
int const N=100000;
int n,v[N],lung[N],urm[N];
int start,maxi;
void citeste ()
{
in>>n;
for(int i=1;i<=n;i++)
in>>v[i];
}
void constr ()
{
for(int i=n;i>0;i--)
{
lung[i]=1;
for(int j=i;j<=n;j++)
{
if((v[i]<v[j])&&(lung[i]<=lung[j]))
{
lung[i]=lung[j]+1;
if(lung[i]>maxi)
{
maxi=lung[i];
start=i;
}
urm[i]=j;
}
}
}
}
void refac ()
{
int j=start;
for(int i=1;i<=maxi;i++)
{
out<<v[j]<<" ";
j=urm[j];
}
}
int main()
{
citeste();
constr();
out<<maxi<<"\n";
refac();
return 0;
}