Pagini recente » Cod sursa (job #373803) | Cod sursa (job #2873434) | Cod sursa (job #2607588) | Cod sursa (job #1673608) | Cod sursa (job #2861965)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int main()
{
int n,tempmax,legnagyobb=0;
f>>n;
int sor[n];
int hossz[n]={0};
for(int i=0;i<n;i++){
f>>sor[i];
}
for(int i=n-1;i>=0;i--){
tempmax=0;
for(int j=i;j<n;j++){
if(sor[j]>sor[i]&&tempmax<hossz[j]){
tempmax=hossz[j];
}
}
hossz[i]=tempmax+1;
if(legnagyobb<hossz[i]){
legnagyobb=hossz[i];
}
}
g<<legnagyobb<<endl;
for(int i=0;i<n;i++){
if(hossz[i]==legnagyobb){
g<<sor[i]<<' ';
legnagyobb--;
}
}
return 0;
}