Cod sursa(job #329695)

Utilizator hasegandaniHasegan Daniel hasegandani Data 7 iulie 2009 10:27:57
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include<stdio.h>

#define nmax 5001

int a[nmax],sol[nmax],inc[nmax];

int main()
{
    int n,max=0;
    freopen("secv.in","r",stdin);
    freopen("secv.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        {
            scanf("%d",&a[i]);
            for(int j=i-1;j;j--)
                if (a[j]<a[i])
                    if (sol[i])
                        if (sol[j]+1>sol[i])
                            {
                            sol[i]=sol[j]+1;
                            if (inc[j])
                                inc[i]=inc[j];
                            else
                                inc[i]=j;
                            }
                        else ;
                    else
                        {
                        sol[i]=sol[j]+1;
                        if (inc[j])
                            inc[i]=inc[j];
                        else
                            inc[i]=j;
                        }
            if (max<i-inc[i])
                max=i;
        }
    printf("%d\n",max);
    return 0;
}