Pagini recente » Profil Iancu007 | Monitorul de evaluare | greseli_destepte | Cod sursa (job #587064) | Cod sursa (job #698935)
Cod sursa(job #698935)
#include <fstream>
using namespace std;
int bst[100069],smax[100069],pre[100069];
int main()
{
int i,j,n,max,sir[100069],imax;
ifstream in ("scmax.in");
ofstream out ("scmax.out");
in>>n;
for (i=1;i<=n;i++)
in>>sir[i];
bst[1]=1;
pre[1]=0;
for (i=2;i<=n;i++)
{
max=0;
for (j=i-1;j>=1;j--)
{
if (max<=bst[j])
{
if (sir[i]>sir[j])
{
bst[i]=bst[j]+1;
pre[i]=j;
max=bst[j];
}
}
}
if (bst[i]==0)
bst[i]=1;
}
max=1;
for (i=1;i<=n;i++)
{
if (bst[i]>max)
{
max=bst[i];
imax=i;
}
}
out<<max<<"\n";
int aux;
aux=max;
while (max)
{
smax[max]=sir[imax];
imax=pre[imax];
max--;
}
for (i=1;i<=aux;i++)
out<<smax[i]<<" ";
out<<"\n";
return 0;
}