Pagini recente » Cod sursa (job #695410) | Cod sursa (job #1847317) | Cod sursa (job #980) | Cod sursa (job #2929756) | Cod sursa (job #3174399)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n;
int a[100005];
int l[100005];
int pozmax=0;
void gasire()
{
for(int i=n; i>=1; i--)
{
l[i] = 1;
for (int j = i + 1; j <= n; j++)
if (a[i] < a[j] && l[j] + 1 > l[i]) {
l[i] = l[j] + 1;
}
pozmax=max(pozmax, l[i]);
}
}
void afisare()
{
for(int i=1; i<=n && pozmax!=0; i++)
{
if(l[i]==pozmax)
{
fout << a[i] << " ";
pozmax--;
}
}
}
int main()
{
fin >> n;
for(int i=1; i<=n; i++)
fin >> a[i];
gasire();
fout << pozmax << "\n";
afisare();
return 0;
}