Pagini recente » Cod sursa (job #3165102) | Cod sursa (job #2771605) | Cod sursa (job #2611310) | Cod sursa (job #2550099) | Cod sursa (job #522214)
Cod sursa(job #522214)
#include<stdio.h>
#include<algorithm>
using namespace std;
struct formatie
{
int x,y;
};
formatie f[100010];
int t[100010];
bool cmp(formatie a,formatie b)
{
return a.y<b.y;
}
int main()
{
freopen("heavymetal.in","r",stdin);
freopen("heavymetal.out","w",stdout);
int last,max,i,n;
scanf("%ld",&n);
for (i=1;i<=n;i++)
scanf("%ld%ld",&f[i].x,&f[i].y);
sort(f+1,f+n+1,cmp);
max=f[n].y;
last=1;
for (i=1;i<=max;i++)
{
t[i]=t[i-1];
while (f[last].y==i)
{
if (t[i]<t[f[max].x]+i-t[f[last].x])
t[i]=t[f[max].x]+i-t[f[last].x];
last++;
}
}
printf("%ld",t[i-1]);
}