Cod sursa(job #2853316)

Utilizator vladburacBurac Vlad vladburac Data 20 februarie 2022 10:32:02
Problema Subsir crescator maximal Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
const int MAXN = 1e5;

ifstream fin( "scmax.in" );
ofstream fout( "scmax.out" );

vector <int> s[MAXN+1];
int main() {
  int n, i, a, st, dr, nr, lenmax, poz, mij;
  fin >> n;
  lenmax = poz = 0;
  nr = 0;
  for( i = 0; i < n; i++ ) {
    fin >> a;
    st = 0;
    dr = nr;
    while( dr - st > 1 ) {
      mij = ( st + dr ) / 2;
      if( s[mij].back() < a )
        dr = mij;
      else
        st = mij;
    }
    if( !s[st].empty() && s[st].back() >= a )
      st++;
    if( s[st].empty() )
      nr++;
    s[st].push_back( a );
    if( s[st].size() > lenmax ) {
      lenmax = s[st].size();
      poz = st;
    }
  }
  fout << lenmax << "\n";
  for( auto it: s[poz] )
    fout << it << " ";
  return 0;
}