Pagini recente » Cod sursa (job #1883664) | Cod sursa (job #3292274) | Cod sursa (job #1361085) | Cod sursa (job #227239) | Cod sursa (job #1503258)
#include <iostream>
#include <fstream>
#define nmax 100001
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int v[nmax],n,l[nmax],c[nmax],xmax;
inline void solve()
{
for(int i=2;i<=n;++i)
{
l[i]=1;
for(int j=1;j<i;++j)
{
if(v[i]>v[j])
if(l[i]<l[j]+1)
{
l[i]=l[j]+1;
c[i]=j;
}
}
if(l[i]>l[xmax])xmax=i;
}
}
inline void read()
{
f>>n;
for(int i=1;i<=n;++i)f>>v[i];
l[1]=1;
}
void write(int x)
{
if(c[x]!=0)
{
write(c[x]);
}
g<<v[x]<<" ";
}
int main()
{
read();
solve();
g<<l[xmax]<<"\n";
write(xmax);
return 0;
}