Cod sursa(job #2807825)

Utilizator MihiBluBalau Mihai MihiBlu Data 24 noiembrie 2021 11:36:57
Problema Subsir crescator maximal Scor 65
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <fstream>
#include <algorithm>
using namespace std;

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

int n, x=0;
long long v[100010], a[100010];

int main()
{
    f>>n;
    for(int i=1; i<=n; i++)
        f>>v[i];
    a[++x]=v[1];
    for(int k=2; k<=n; k++)
    {
        if(v[k]>a[x])
        {
            x++;
            a[x]=v[k];
        }
        else
        {
            int st=1, dr=x, poz=0;
            while(st<=dr)
            {
                int mij=(st+dr)/2;
                if(a[mij]>=v[k])
                    dr=mij-1, poz=mij;
                else
                    st=mij+1;
            }
            a[poz]=v[k];
        }
    }
    g<<x<<'\n';
    for(int i=1; i<=x; i++)
        g<<a[i]<<" ";
    return 0;
}