Pagini recente » Cod sursa (job #2936432) | Cod sursa (job #2290199) | Cod sursa (job #2353735) | Cod sursa (job #2931592) | Cod sursa (job #1498778)
#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] && 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]<<endl;
write(xmax);
return 0;
}