Pagini recente » Cod sursa (job #1197360) | Cod sursa (job #415642) | Cod sursa (job #639348) | Cod sursa (job #1942221) | Cod sursa (job #1582943)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
const int N=100001;
int v[N],lung[N],pred[N],n,lmax;
void refacsir(int p){
if(pred[p]!=0)
refacsir(pred[p]);
out<<v[p]<<" ";
}
int main()
{
int pmax;
in>>n;
for(int i=1;i<=n;i++){
in>>v[i];
}
lung[1]=1;
pmax=1;
for(int i=2;i<=n;i++){
lmax=0;
pred[i]=0;
for(int j=1;j<i;j++)
if(v[j]<v[i])
if(lung[j]>lmax){
lmax=lung[j];
pred[i]=j;
}
lung[i]=1+lmax;
if(lung[i]>lung[pmax])
pmax=i;
}
out<<lung[pmax]<<"\n";
refacsir(pmax);
return 0;
}