Cod sursa(job #3364519)

Utilizator Alexandru_OrzeaOrzea Alexandru Alexandru_Orzea Data 4 septembrie 2026 19:25:24
Problema Subsir crescator maximal Scor 55
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.12 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
#include <fstream>

using namespace std;

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

long long n, mx, dp[100000], m[100000], sir[100000], pozx, z;

int main()
{
    f>>n;
    
    for(int i=0; i<n; i++){
        f>>m[i];
        
        for(int j=i-1; j>=0; j--)
            if(m[j] < m[i])
                dp[i] = max(dp[i], dp[j]);
                
        dp[i]++;
        
        if(dp[i] > mx){
        mx = dp[i];
        pozx = i;
        }
    }
    
    g<<mx<<'\n';
    
    sir[0] = m[pozx];
    
    
    for(z=1; z<mx; z++){
    sir[z] = 2000000000;
        
    for(int i=pozx-1; i>=0; i--)
        if(dp[i] == mx-z && sir[z-1] > m[i]){
        sir[z] = min(sir[z], m[i]); 
        pozx = i;
        }
}

for(int i=z-1; i>=0; i--)
g<<sir[i]<<' ';

    return 0;
}