Pagini recente » Cod sursa (job #773200) | Cod sursa (job #1184944) | Cod sursa (job #95870) | Cod sursa (job #661196) | Cod sursa (job #1329566)
#include <iostream>
#include <cstdio>
#define n_max 100005
using namespace std;
int n , v[n_max] , ant[n_max] , val[n_max] , pp , mx ;
void khepis() ;
void cacarnitza() ;
void rahatzire( int p ) ;
int main()
{
freopen( "scmax.in" , "r" , stdin ) ;
freopen( "scmax.out" , "w" , stdout ) ;
khepis() ;
printf( "%d\n" , mx + 1 ) ;
rahatzire( pp ) ;
return 0;
}
void cacarnitza( int pos )
{
for ( int j = pos - 1 ; j > 0 ; j -- )
if ( v[j] < v[pos] && val[j] + 1 > val[pos] )
{
ant[pos] = j ;
val[pos] = val[j] + 1 ;
}
}
void khepis()
{
val[0] = -1 ;
scanf( "%d" , &n ) ;
for ( int i = 1 ; i <= n ; i ++ )
{
scanf( "%d" , &v[i] ) ;
cacarnitza(i) ;
if ( val[i] > mx )
{
mx = val[i] ;
pp = i ;
}
}
}
void rahatzire( int p )
{
if ( ant[p] )
rahatzire( ant[p] ) ;
printf( "%d " , v[p] ) ;
}