Cod sursa(job #214946)

Utilizator Andrei200Andrei200 Andrei200 Data 16 octombrie 2008 22:49:30
Problema Heavy metal Scor 40
Compilator c Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <stdio.h>

int n,i,j,Best[100000],b[100000],a[100000],maxim,x,y;
char ch[30];

int max(int a,int b)
{
    if (a>b)
    return a;
    else
    return b;
}

int main()
{
    freopen("heavymetal.in","rt",stdin);
    scanf("%d", &n);
    //freopen("heavymetal.out","wt",stdout);
    gets(ch);
     for (i=1;i<=n;++i)
          {
               // scanf("%d %d", &a[i],&b[i]);
           gets(ch);
           x=y=j=0;
           while (ch[j]!=' ')
                  {
                        x=x*10+ch[j]-'0';
                        j++;
                        }
                        j++;
           while (ch[j])
           {
                y=y*10+ch[j]-'0';
                j++;
                }
            a[i]=x;
            b[i]=y;  
           // printf("%d %d\n", x,y);
            maxim=max(maxim,b[i]);
        }
    for (i=1;i<=maxim;++i)
          {    
            Best[i]=Best[i-1];   
           for (j=1;j<=maxim;++j)
           if (b[j]==i)   
        Best[i]=max(Best[i],Best[a[j]]+(b[j]-a[j]));  
}

freopen("heavymetal.out","wt",stdout);
printf("%ld", Best[maxim]);
return 0;
}