Pagini recente » Cod sursa (job #2360388) | Cod sursa (job #764194) | Cod sursa (job #1641159) | Cod sursa (job #666353) | Cod sursa (job #2963603)
#include <fstream>
using namespace std;
const int N = 1e5;
int n, x[N + 1], lung[N + 1], pmax;
ifstream in("scmax.in");
ofstream out("scmax.out");
void refac_subsir(int p, int l, int val)
{
if (l == 0)
{
return;
}
if (lung[p]==l && x[p]<val)
{
refac_subsir(p-1,l-1,x[p]);
out << x[p] << " ";
}
else
{
refac_subsir(p-1,l,val);
}
}
int main()
{
int n;
in>>n;
int pmax=1;
for(int i=1;i<=n;i++)
{
int l_j=0;
in>>x[i];
for(int j=1;j<i;j++)
{
if(x[j]<x[i])
{
if(lung[j]>l_j)
{
l_j=lung[j];
}
}
}
lung[i]=1+l_j;
if(lung[i]>lung[pmax])
{
pmax=i;
}
}
out<<lung[pmax]<<"\n";
refac_subsir(pmax, lung[pmax], x[pmax]+1);
in.close();
out.close();
return 0;
}