Pagini recente » Diferente pentru admin/task-ratings-guidelines intre reviziile 27 si 26 | Cod sursa (job #1809307) | Cod sursa (job #111471) | Borderou de evaluare (job #1512370) | Cod sursa (job #3337136)
#include <stdio.h>
int d[100000];
int cautBin( int a[], int st, int dr, int x ) {
int mj;
while ( st + 1 < dr ) {
mj = (st + dr) / 2;
if ( a[mj] < x )
st = mj;
else
dr = mj;
}
return dr;
}
int main() {
FILE *fin, *fout;
int n, i, x, pos, lmax = 0;
fin = fopen( "scmax.in", "r" );
fscanf( fin, "%d", &n );
for ( i = 0; i < n; i++ ) {
fscanf( fin, "%d", &x );
pos = cautBin( d, -1, lmax, x );
d[pos] = x;
if ( lmax == pos )
lmax++;
}
fclose( fin );
fout = fopen( "scmax.out", "w" );
fprintf( fout, "%d\n", lmax );
for ( i = 0; i < lmax; i++ )
fprintf( fout, "%d ", d[i] );
fclose( fout );
return 0;
}