Pagini recente » Cod sursa (job #1043446) | Cod sursa (job #2135235) | Cod sursa (job #730554) | Cod sursa (job #1260733) | Cod sursa (job #2326129)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int v[100000] , vd[100000] , vp[100000] , nou[100000];
int main()
{
int n;
fin >> n;
for(int i = 1; i <= n ; ++i)
fin >> v[i];
int maxim = 0 , p_max;
for(int i = 1; i <= n; ++i)
{
vd[i] = 1;
for( int j = i ; j >= 1 ; --j)
{
if( v[i] > v[j] && vd[i] <= vd[j])
{
vd[i] = vd[j]+1;
vp[i] = j;
if(vd[i] > maxim)
{
p_max = i;
maxim = vd[i];
}
}
}
}
fout << vd[p_max] << '\n';
nou[vd[p_max]] = v[p_max];
for( int i = p_max , j = 1 ; j < vd[p_max] ; ++j)
{
nou[vd[p_max]-j] = v[vp[i]];
--i;
}
for( int i = 1 ; i <= vd[p_max] ; ++i )
fout << nou[i] << " ";
}