Cod sursa(job #175935)

Utilizator AlxCojocaru Alexandru Alx Data 10 aprilie 2008 16:48:01
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <stdio.h>
int n,a[100001],l[100001],best[100001],p[100001],nr;
int caut(int x)
{
    int st=0,sf=nr,m=(st+sf)/2;
    while (st<=sf)
    {
        if (a[l[m]]<x&&a[l[m+1]]>=x)
         return m;
        if (a[l[m+1]]>x)
        {
            st=m+1;
            m=(st+sf)/2;
        }
        else
        {
            sf=m-1;
            m=(st+sf)/2;
        }
    }
    return nr;
}
int main()
{
    freopen("scmax.in","r",stdin);
    freopen("scmax.out","w",stdout);
    scanf("%d",&n);
    int i,poz;
    for (i=1;i<=n;i++)
        scanf("%d",&a[i]);
    l[i]=best[i]=1;
    nr=1;
    for (i=2;i<=n;i++)
    {
        poz=caut(a[i]);
        best[i]=poz+1;
        p[i]=l[poz];
        l[poz+1]=i;
        if (poz+1>nr)
         nr=poz+1;
    }
    return 0;
}