Cod sursa(job #871721)
| Utilizator | Data | 5 februarie 2013 09:27:24 | |
|---|---|---|---|
| Problema | Heavy metal | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.53 kb |
#include<cstdio>
#include<algorithm>
using namespace std;
long n,a[100001],b[100001];
long best[100001];
long i,g,tmax;
int main()
{
freopen ("heavymetal.in","r",stdin);
freopen ("heavymetal.out","w",stdout);
scanf("%ld",&n);
for(i=1;i<=n;i++)
{
scanf("%ld%ld",&a[i],&b[i]);
if(b[i]>tmax)
tmax=b[i];
}
for(i=1;i<=tmax;i++)
{
best[i]=best[i-1];
for(long j=1;j<=n;j++)
if(b[j]==i)
best[i]=max(best[i],best[a[j]]+(b[j]-a[j]));
}
printf("%ld\n",best[tmax]);
return 0;
}
