Pagini recente » Cod sursa (job #582944) | Cod sursa (job #1709650) | Cod sursa (job #2194020) | Cod sursa (job #2832974) | Cod sursa (job #1867047)
#include <fstream>
using namespace std;
ifstream cin("scmax.in");
ofstream cout("scmax.out");
const int MAX = 100005;
int n, v[MAX], lung[MAX], pred[MAX];
void sir(int p){
if(pred[p]!=0){
sir(pred[p]);
}
cout<<v[p]<<' ';
}
int main()
{
cin>>n;
for(int i=1; i<=n; ++i)
cin>>v[i];
for(int i=1; i<=n; ++i){
int lmax = 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;
}
int pmax =1;
for(int i=2; i<=n; ++i)
if(lung[i] > lung[pmax]){
pmax = i;
}
cout<<lung[pmax]<<'\n';
sir(pmax);
return 0;
}