Pagini recente » Cod sursa (job #2680980) | Cod sursa (job #1431863) | Cod sursa (job #2860165) | Cod sursa (job #1498283) | Cod sursa (job #871721)
Cod sursa(job #871721)
#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;
}