Pagini recente » Cod sursa (job #1922146) | Cod sursa (job #2852545) | Cod sursa (job #900984) | Cod sursa (job #566978) | Cod sursa (job #1160652)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int v[100010],poz[100010],lung[100010],a,b,x,k,maxi,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;
for(i=n ; 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,j,k;
i=tot;
k=toti;
for(j=1 ; j<=k; j++)
{
fout<<v[i]<<" ";
i=poz[i];
}
}
int main()
{
citire();
rezolvare();
total();
fout<<toti<<"\n";
afisare();
fin.close();
fout.close();
return 0;
}