Cod sursa(job #2616074)

Utilizator betybety bety bety Data 16 mai 2020 16:27:28
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.95 kb
#include <bits/stdc++.h>







using namespace std;







#define N 100005







ifstream fin ("scmax.in");







ofstream fout ("scmax.out");







int a[N];







int aux[N];







int cur[N];







int ant[N];







int l = 0;







int n;







int cauta (int x, int lun)







{







    int st, dr;







    st= 1;







    dr = lun;







    while (st < dr)







    {







        int mij = (st + dr) / 2;







        if (x > aux[mij])







            st = mij + 1;







        else







         dr = mij;







    }







    return st;







}







void tipar (int poz)







{







    if (poz == 0)







        return;







    else







    {







        tipar (ant[poz]);







        fout << a[poz] << " ";







    }







}







int main ()







{







    fin >> n;







    for (int i = 1; i <= n; i++)







        fin >> a[i];







    aux[1] = a[1];







    cur[1] = 1;







    l++;







    for (int i = 2; i <= n; i++)







    {







         int x = cauta (a[i], l);










         if (a[i] > aux[x])







         {







            aux[++l] = a[i];







            cur[l] = i;







            ant[i] = cur[l - 1];







         }







         else







         {







            aux[x] = a[i];







            cur[x] = i;







            ant[i] = cur[x - 1];







         }







    }







    fout << l << "\n";







    tipar (cur[l]);







}