Pagini recente » Cod sursa (job #388808) | Cod sursa (job #1320119) | Cod sursa (job #551239) | Cod sursa (job #1887650) | Cod sursa (job #1585573)
#include <iostream>
#include <fstream>
#define maxn 100005
using namespace std;
int main()
{int i,n,max,v[maxn],poz[maxn],best[maxn],p,x,j;
fstream f("scmax.in",ios::in);
fstream g("scmax.out",ios::out);
f>>n;
for(i=1;i<=n;i++)
{f>>v[i];best[i]=1;poz[i]=i;}
max=0;
poz[1]=1;
for(i=2;i<=n;i++)
for(j=1;j<i;j++)
if((v[j]<v[i])&&(best[i]<best[j]+1))
{best[i]=best[j]+1;
poz[i]=poz[j];
if(best[i]>max)
{max=best[i];
p=i;}
}
g<<max<<'\n';
x=1;
for(i=poz[p];((i<=n)&&(x<=best[p]));i++)
if(best[i]==x)
{g<<v[i]<<" ";
x++;
}
f.close();
g.close();
}