Cod sursa(job #2982099)

Utilizator bitza1247Stanciu-Tivlea Valentin Gabriel bitza1247 Data 19 februarie 2023 15:41:31
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
///prima care nu e mai mica   lower
///prima care e mai mare   upper
#include <bits/stdc++.h>

using namespace std;

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

long long n,m,i,j,x,k,A[100002],v[100002],I[100002],y[100002];

int main()
{
    f>>n;
    for(i=1; i<=n; i++)
    {
        f>>x;
        y[i]=x;
        if(x>v[k])
        {
            v[++k]=x;
            A[i]=k;
        }
        else
        {
            auto p=lower_bound(v,v+k,x);
            v[p-v]=x;
            A[i]=p-v;
        }
    }
    g<<k<<'\n';
    m=k;
    for(i=n; i>=1; i--)
    {
        while(A[i]!=m)
        {
            i--;
        }
        I[m]=i;
        m--;
    }
    for(i=1; i<=k; i++)
    {
        g<<y[I[i]]<<' ';
    }
    return 0;
}