Cod sursa(job #3337136)

Utilizator calinulCalin Cernat calinul Data 26 ianuarie 2026 22:36:14
Problema Subsir crescator maximal Scor 65
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#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;
}