Pagini recente » Cod sursa (job #1266677) | Cod sursa (job #467063) | Cod sursa (job #2503014) | Cod sursa (job #2282558) | Cod sursa (job #690602)
Cod sursa(job #690602)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
const int N=100001;
int v[N],lung[N],n,nr[N];
int maxim()
{
int a=0;
for(int i=1;i<=n;i++)
if(lung[i]>a)
a=lung[i];
return a;
}
/*void afisare()
{
for(int i=1;i<=n;i++)
{
cout<<lung[i]<<' ';
}
cout<<"\n";
for(int i=1;i<=n;i++)
{
cout<<nr[i]<<" ";
}
}*/
void lungime()
{
int i,j;
lung[1]=1;nr[1]=1;
for(i=2;i<=n;i++)
{
lung[i]=0;
for(j=1;j<i;j++)
{
if(v[j]>=v[i]) continue;
if(lung[j]==lung[i]) nr[i]+=nr[j];
if(lung[j]>lung[i])
{
nr[i]=nr[j];
lung[i]=lung[j];
}
}
lung[i]++;
}
return;
}
int main()
{
int i=1,poz=1,max=0;
in>>n;
for(i=1;i<=n;i++)
in>>v[i];
lungime();
max=maxim();
out<<max<<"\n";
//afisare();
for(i=1;i<=max;i++)
{
while( poz<=n && lung[poz]==i )
poz++;
out<<v[poz-1]<<' ';
}
return 0;
}