Pagini recente » Cod sursa (job #2393316) | Cod sursa (job #2957035) | Cod sursa (job #2122749) | Cod sursa (job #2897306) | Cod sursa (job #140645)
Cod sursa(job #140645)
#include<stdio.h>
//#include<algorithm>
#define NMAX 101001
//using namespace std;
long p,i,y[NMAX],poz,in,sf,a,j,k,l,n,m,q;
struct kkt
{
long X,Y;
};
kkt x[NMAX],aux;
/*int cmpf(const kkt a,const kkt b)
{
return a.Y>b.Y;
} */
long mx(long a,long b)
{
if (a>b) return a;
return b;
}
int main()
{
freopen("heavymetal.in","r",stdin);
freopen("heavymetal.out","w",stdout);
scanf("%ld",&n);
for (i=1;i<=n;i++)
scanf("%ld%ld",&x[i].X,&x[i].Y);
a=1;
while (a)
{
a=0;
for (i=1;i<n;i++)
if (x[i].Y>x[i+1].Y)
{
aux=x[i];
x[i]=x[i+1];
x[i+1]=aux;
a=1;
}
}
// sort(x+1,x+n+1,cmpf);
for (i=1;i<=n;i++)
{
y[x[i].Y]=y[x[i].Y-1];
for (j=1;j<=n;j++)
if (x[j].Y==x[i].Y)
y[x[i].Y]+=mx(y[x[i].Y],y[x[j].X]+(x[j].Y-x[j].X));
if (y[x[i].Y]>p)
p=y[x[i].Y];
}
printf("%ld\n",p);
return 0;
}