Pagini recente » Cod sursa (job #2815609) | Cod sursa (job #663660) | Cod sursa (job #394621) | Cod sursa (job #1125711) | Cod sursa (job #2891181)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
#define MAXN 100000
int best[MAXN], a[MAXN], prev[MAXN];
void reconst(int poz)
{
if(poz == -1)
return ;
reconst(prev[poz]);
fout << a[poz] << " ";
}
int main()
{
int i, j, n, maxx, poz, maxxsir = 0, finall = 0;
fin >> n;
for(i = 0; i < n; i++)
{
fin >> a[i];
maxx = 0;
poz = -1;
for(j = 0; j < i; j++)
if(best[j] > maxx && a[j] < a[i])
{
maxx = best[j];
poz = j;
}
best[i] = maxx + 1;
prev[i] = poz;
if(best[i] > maxxsir)
{
maxxsir = best[i];
finall = i;
}
}
fout << maxxsir << "\n";
reconst(finall);
return 0;
}