Pagini recente » Cod sursa (job #1251354) | Cod sursa (job #1157622) | Cod sursa (job #2241293) | Cod sursa (job #2744722) | Cod sursa (job #2457695)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int v[100000], l[100000], pred[100000], maxi, a, pmax, lc;
void subsir(int p)
{
if(pred[p] != 0){
subsir(pred[p]);
}
out << v[p] << " ";
}
int main()
{
int n;
in >> n;
for(int i = 0; i < n; i++){
in >> v[i];
lc = 0;
for(int j = 0; j < i; j++){
if(v[j] < v[i]){
if(v[j] > lc){
lc = l[j];
pred[i] = j;
}
}
}
l[i] = 1 + lc;
if(l[i] > l[pmax]){
pmax = i;
}
}
out << l[pmax] << "\n";
subsir(pmax);
return 0;
}