Pagini recente » Cod sursa (job #2117530) | Cod sursa (job #531197) | Cod sursa (job #751586) | Cod sursa (job #1515615) | Cod sursa (job #1045265)
#include <vector>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream is("scmax.in");
ofstream os("scmax.out");
int n, lmax, nr;
vector<long long int> a, L, t;
void Path( int i );
int BinarySearch( int x, int st, int dr );
int main()
{
is >> n;
a.resize( n + 1);
for ( int i = 1; i <= n; i++ )
is >> a[i];
L.resize( n + 1);
t.resize( n + 1);
for ( int i = 1; i <= n; i++ )
{
int j = BinarySearch( i, 1, lmax );
L[i] = t[j];
t[j+1] = i;
lmax = max ( lmax, j + 1 );
}
os << lmax << '\n';
Path( t[lmax] );
is.close();
os.close();
return 0;
}
int BinarySearch( int x, int st, int dr )
{
int mij;
while ( st <= dr )
{
mij = (st + dr) / 2;
if ( a[t[mij]] < a[x] )
st = mij + 1;
else
dr = mij - 1;
}
return dr;
}
void Path( int i )
{
if ( i == 0 ) return;
Path( L[i] );
os << a[i] << ' ';
}