Pagini recente » Cod sursa (job #1537937) | Cod sursa (job #1324650) | Cod sursa (job #1390820) | Cod sursa (job #1202195) | Cod sursa (job #350567)
Cod sursa(job #350567)
/*
* File: main.cpp
* Author: speedemon
*
* Created on September 19, 2009, 6:06 PM
*/
#include <fstream>
#include <cstdlib>
#define InFile "roci.in"
#define OutFile "roci.out"
/*
*
*/
using namespace std;
ifstream in;
ofstream out;
int main()
{int N,i,j=0,st,dr,m,L=0;
int *v,*M;
in.open(InFile);
in>>N;
v=(int*)calloc( N, sizeof(int) );
M=(int*)calloc( N, sizeof(int) );
for( i=0; i < N; ++i ) in>>v[i];
for( i=1; i < N; ++i )
{ st=0; dr=i;
while( st < dr )
{
m=st+(dr-st)/2;
if( v[M[m]] < v[i] && v[M[m+1]] >= v[i] )
{
j=m;
break;
}
else if( v[M[m]] >= v[i] ) dr=m-1;
else st=m+1;
}
if( st == dr ) j=0;
if( j == L || v[i] < v[M[j+1]] )
{
M[j+1]=i;
}
if( L < j+1 ) L=j+1;
}
out.open(OutFile);
out<<L;
free(v); free(M);
return EXIT_SUCCESS;
}