Cod sursa(job #1656172)

Utilizator hegedusPaul Hegedus hegedus Data 18 martie 2016 20:54:30
Problema Subsir crescator maximal Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <cstdio>
using namespace std;

const long nmax=100001;

struct w{unsigned long val; unsigned long x;};
struct w rangmax;
unsigned long n,x,y,v[nmax],rang[nmax];

void citire()
{
    freopen("scmax.in","r",stdin);
    freopen("scmax.out","w",stdout);
    scanf("%ld",&n);
    for(x=1;x<=n;x++)
        scanf("%ld",&v[x]);
}

int main()
{
    citire();
    for(x=n;x>=1;x--)
    {
        for(y=x+1;y<=n;y++)
            if(v[y]>v[x] && rang[y]>rang[x])
                rang[x]=rang[y]+1;
        if (!rang[x]) rang[x]=1;
        if (rang[x]>rangmax.val){rangmax.val=rang[x]; rangmax.x=x;}
    }

    printf("%ld\n",rangmax.val);
    for(x=rangmax.x;x<=n;x++)
    {
        if (rang[x]==rangmax.val)
        {
            rangmax.val--;
            printf("%ld ",v[x]);
        }
    if (!rangmax.val) {printf("\n");return 0;}
    }
}