Pagini recente » Cod sursa (job #2839477) | Cod sursa (job #1753882) | Cod sursa (job #141305) | Cod sursa (job #2175197) | Cod sursa (job #2292607)
#include <iostream>
#include <climits>
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
const int nmax=100005;
int a[nmax], lmax[nmax], pre[nmax], maxim=INT_MIN, best, k;
void cresc(int best){
if(best==0) return;
cresc(pre[best]);
fout<<a[best]<<" ";
}
int main(){
int n;
fin >> n;
for(int i=1; i <= n; i++){
fin >> a[i];
}
for(int i=1; i<=n; i++){
lmax[i] = 1;
for(int j=1; j<=i-1; j++){
if(a[i]>a[j]){
if(lmax[i]<lmax[j]+1){
lmax[i]=lmax[j]+1;
pre[i]=j;
}
}
}
if(lmax[i]>maxim){
maxim=lmax[i];
best=i;
}
}
fout << maxim << '\n';
/*while(lmax[best]!=1){
cout<<a[best]<<" ";
best=pre[best];
}*/
cresc(best);
return 0;
}