Pagini recente » Cod sursa (job #2873384) | Cod sursa (job #361169) | Cod sursa (job #2593228) | Cod sursa (job #2801133) | Cod sursa (job #2861953)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int main()
{
int n,tempmax=-1,legnagyobb;
f>>n;
int sor[n];
int maxi[n]={0};
maxi[n-1]=1;
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<maxi[j]){
tempmax=maxi[j];
}
}
maxi[i]=tempmax+1;
if(legnagyobb<maxi[i]){
legnagyobb=maxi[i];
}
}
g<<legnagyobb<<endl;
for(int i=0;i<n;i++){
if(maxi[i]==legnagyobb){
g<<sor[i]<<' ';
legnagyobb--;
}
}
return 0;
}