Cod sursa(job #1208657)

Utilizator fromzerotoheroFROM ZERO fromzerotohero Data 16 iulie 2014 12:22:52
Problema Subsir crescator maximal Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;

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

int n,i,j,k=1,poz;
long Lmax;
int A[nmax],L[nmax];
vector <int> H[nmax];

int cautBin(int h, int x) {
    
    int lo = 1;
    int hi = h;
    
    while (hi - lo > 1) {
        
        int mid = (hi + lo) / 2;
        
        L[mid] > x ? lo = mid : hi = mid;
        
    }
    
    return hi;
}

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

}

void lucru() {
    
    L[1] = A[1];
    H[1].push_back(A[1]);
    
    for (i=2; i<=n; i++) {
        
        int x = cautBin(k, A[i]);
        
        if (L[x] < A[i]) {
            H[x].push_back(A[i]);
            Lmax < H[x].size() ? (Lmax  = H[x].size(), poz = x) : Lmax ;
            L[x] = A[i];
        } else
            L[++k] = A[i], H[k].push_back(A[i]);
    }
    
    out << Lmax << "\n";
    
    for (i=0; i<Lmax; i++)
        out << H[poz][i] << " ";

}

int main(){
    
    citire();
    lucru();
    
    return 0;
}