Cod sursa(job #1550740)

Utilizator dex4Darjan Catalin dex4 Data 14 decembrie 2015 17:26:33
Problema Subsir crescator maximal Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <iostream>
#include <fstream>
#define nmax 100005

using namespace std;

int n, a[nmax], in, out, bi, bo, best, lmax;

void read(){
    int x = 1, i=1;
    ifstream f("scmax.in");
    f >> n;
    f >> a[1];
    while(!f.eof()){
        f >> x;
        if(x != a[i]){
            i++;
            a[i] = x;
        }
    }
    n = i;
}

void solve(){
    in = out = 1;
    bi = bo = 1;
    best = -1;
    lmax = 1;
    for(int i = 1; i < n; i++){
        if(a[i] < a[i+1]){
            lmax++;
            out = i+1;
            if(lmax > best){
                best = lmax;
                bi = in;
                bo = out;
                //cout << best << " " << bi << " " << bo << "\n";
            }
        }
        else{
            lmax = 1;
            in = out = i+1;
        }
    }
}

int main()
{
    read();
    solve();
    ofstream g("scmax.out");
    g << best << "\n";
    for(int i=bi; i<=bo; i++)
        g << a[i] << " ";
    return 0;
}