Pagini recente » Cod sursa (job #2594664) | Cod sursa (job #2191724) | Cod sursa (job #828498) | Cod sursa (job #2187799) | Cod sursa (job #1045148)
#include <vector>
#include <fstream>
using namespace std;
ifstream is("scmax.in");
ofstream os("scmax.out");
int n, lmax, pmax;
vector<long long int> a, L, t;
void Path( int i );
int main()
{
is >> n;
a.resize( n + 1);
L.resize( n + 1);
t.resize( n + 1);
for ( int i = 1; i <= n; i++ )
{
is >> a[i];
L[i] = 1;
for ( int j = 1; j < i; j++ )
if ( L[i] < L[j] + 1 && a[i] > a[j] )
L[i] = L[j] + 1, t[i] = j;
if ( L[i] > lmax )
lmax = L[i], pmax = i;
}
os << lmax << '\n';
Path( pmax );
is.close();
os.close();
return 0;
}
void Path( int i )
{
if ( i == 0 ) return;
Path( t[i] );
os << a[i] << ' ';
}