Cod sursa(job #2291799)

Utilizator XibronSomai Norbert-Attila Xibron Data 28 noiembrie 2018 17:31:48
Problema Subsir crescator maximal Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <climits>

using namespace std;

void beolvas(int *&t, int &n)
{
    freopen("scmax.in", "r", stdin);
        freopen("scmax.out", "w", stdout);
    cin>>n;
    t = (int *)malloc((n+1)*sizeof(int));
    for(int i = 1; i<=n; i++)
        cin>>t[i];
    t[0] = 0;
}

int main()
{
    int *t, n, *temp, MAX, maxh;
    beolvas(t,n);
    temp = (int *)calloc(n+1,sizeof(int));
    temp[n] = 1;
    for(int i = n-1; i>=0; i--)
    {
        MAX = INT_MIN;
        for(int j = i; j<=n; j++)
        {
            if(t[i]<t[j])
                if(temp[j]>MAX)
                    MAX = temp[j];
        }
        temp[i] = MAX + 1;
    }
    cout<<temp[0]-1<<endl;
    int a = temp[0]-1;
    for(int i = 1; i<=n; i++)
    {
        if(temp[i] == a)
        {
            cout<<t[i]<<' ';
            a--;
        }
    }

    free(temp);
    free(t);
    return 0;
}