Pagini recente » Cod sursa (job #2339149) | Cod sursa (job #2948290) | Cod sursa (job #1980544) | Cod sursa (job #3289205) | Cod sursa (job #2963593)
#include <fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
const int N = 1e6;
int l[N + 1] , x[N + 1] , n;
void refac_subsir(int dmax , int lmax , int val){
if(lmax == 0){
return;
}
if(x[dmax] < val && l[dmax] == lmax){
refac_subsir(dmax - 1 , lmax - 1 , x[dmax]);
out << x[dmax] << ' ';
}
else{
refac_subsir(dmax - 1 , lmax , val);
}
}
int main(){
in >> n;
for(int i = 1 ; i <= n ; i++){
in >> x[i];
}
int poz_max = 1;
for(int i = 1 ; i <= n ; i++){
int l_max_i = 0;
for(int j = 1 ; j < i ; j++){
if(x[j] < x[i]){
if(l[j] > l_max_i){
l_max_i = l[j];
}
}
}
l[i] = 1 + l_max_i;
if(l[i] > l[poz_max]){
poz_max = i;
}
}
out << l[poz_max] << '\n';
refac_subsir(poz_max , l[poz_max] , x[poz_max] + 1);
}