Cod sursa(job #1210005)

Utilizator fromzerotoheroFROM ZERO fromzerotohero Data 18 iulie 2014 23:36:28
Problema Subsir crescator maximal Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

#define nmax 100001
ifstream fi("scmax.in");
ofstream out("scmax.out");

int n,i,j,poz;
long Lmax;
int A[nmax],L[nmax];
vector <int> B[nmax];

void citire() {
    fi >> n;
    for (i=1; i<=n; i++)
        fi >> A[i];
}

void lucru() {
    
    int k = 1;
    
    B[k].push_back(A[1]);
    
    L[k] = A[1];
    
    for (i=2; i<=n; i++) {
        
        bool ok = true;
        
        for (j=1; j<=k; j++)
            if (A[i] > L[j]) {
                L[j] = A[i],
                B[j].push_back(A[i]),
                ok = false;
        
                if (Lmax < B[j].size()) {
                    Lmax = B[j].size();
                    poz = j;
                }
                
                break;
            }
        
        if (ok)
            L[++k] = A[i],
            B[k].push_back(A[i]);
        
    }
    
    out << Lmax << "\n";
    
    for (i=0; i<Lmax; i++)
        out << B[poz][i] << " ";
    
    out << "\n";
        
}

int main(){

    citire();
    lucru();
    
    return 0;
}