Pagini recente » Cod sursa (job #2919461) | Cod sursa (job #2347434) | Cod sursa (job #8762) | Cod sursa (job #3251257) | Cod sursa (job #1160661)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int v[100010],poz[100010],lung[100010],a,b,x,k,tot,n,toti;
void citire ()
{ int i;
fin>>n;
for(i=1 ; i<=n ; i++)
{
fin>>v[i];
lung[i]=1;
}
}
void rezolvare ()
{int i,j,maxi;
for(i=n-1 ; i>=1 ; i--)
{
maxi=1;
for(j=i+1 ; j<=n ; j++)
{
if(v[i]<v[j])
a=lung[j]+1;
if(a>=maxi)
{
maxi=a;
lung[i]=a;
poz[i]=j;
}
}
}
}
void total ()
{int i;
for(i=1 ; i<=n ; i++)
if(lung[i]>toti)
{
toti=lung[i];
tot=i;
}
}
void afisare()
{int i,k;
i=tot;
k=toti;
while(poz[i]!=0)
{
fout<<v[i]<<" ";
i=poz[i];
}
}
int main()
{
citire();
rezolvare();
total();
fout<<toti<<"\n";
afisare();
fin.close();
fout.close();
return 0;
}