Cod sursa(job #2575779)

Utilizator Florinos123Gaina Florin Florinos123 Data 6 martie 2020 15:22:44
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <fstream>

using namespace std;

ifstream f ("scmax.in");
ofstream g ("scmax.out");

int n, lg;
int subsir[100005];
int v[100005];
int ant[100005];

int binary (int x, int poz)
{
   int st = 1, dr = poz, rez = 0, mij;
    while (st <= dr)
    {
        mij = (st + dr) / 2;
         if (v[subsir[mij]] < x)
         {
             rez = mij;
             st = mij + 1;
         }
         else dr = mij - 1;
    }
   return rez;
}

void Print (int poz)
{
  if (ant[poz])
     Print(ant[poz]);
  g << v[poz] << " ";
}

int main()
{
  f >> n;
   for (int i=1; i<=n; i++)
   {
       f >> v[i];
       int poz = binary(v[i], lg);
       if (poz == lg) lg ++;
       subsir[poz+1] = i;
       ant[i] = subsir[poz];
   }

  g << lg << '\n';
  Print(subsir[lg]);
    return 0;
}