Cod sursa(job #3284926)

Utilizator Dia3141Costea Diana Stefania Dia3141 Data 12 martie 2025 12:55:16
Problema Subsir crescator maximal Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <fstream>
#define nmax 100001
using namespace std;
ifstream cin("scmax.in");
ofstream cout("scmax.out");
int n,v[nmax],dp[nmax],t[nmax],k;
void rec(int n){
    if(t[n]!=0)
        rec(t[n]);
    cout<<v[n]<<" ";
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>v[i];
        int st=1,dr=k,poz=0;
        while(st<=dr){
            int mid=(st+dr)/2;
            if(v[dp[mid]]>=v[i])
                poz=mid,dr=mid-1;
            else
                st=mid+1;
        }
        if(poz==0){
            t[i]=dp[k];
            dp[++k]=i;
        }else{
            t[i]=dp[poz-1];
            dp[poz]=i;
        }
    }
    cout<<k<<'\n';
    rec(dp[k]);
    return 0;
}