Pagini recente » Cod sursa (job #681140) | Cod sursa (job #2380129) | Cod sursa (job #116744) | Cod sursa (job #1492687) | Cod sursa (job #2959246)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
const int Nmax = 100000;
int v[Nmax], best[Nmax], prv[Nmax];
void reconst(int x){
if(prv[x] == -1){
fout << v[x] << " ";
return;
}
reconst(prv[x]);
fout << v[x] << " ";
}
int main()
{
int n, lenmax, x;
bool ok;
fin >> n;
lenmax = 0;
x = 0;
for(int i = 0; i < n; i++){
fin >> v[i];
ok = 0;
for(int j = 0; j < i; j++){
if(v[i] > v[j]){
if(best[i] < best[j] + 1){
best[i] = best[j] + 1;
prv[i] = j;
ok = 1;
}
}
}
if(ok == 0){
best[i] = 1;
prv[i] = -1;
}
if(lenmax < best[i]){
lenmax = best[i];
x = i;
}
}
fout << lenmax << '\n';
reconst(x);
return 0;
}