Pagini recente » Cod sursa (job #2253404) | Cod sursa (job #2783033) | Cod sursa (job #1843766) | Cod sursa (job #2901987) | Cod sursa (job #139321)
Cod sursa(job #139321)
#include<stdio.h>
#include<algorithm>
#define NMAX 50051
using namespace std;
long n,m,a,i,s,mx,k,l,q;
struct kkt
{
long X,Y;
};
kkt x[NMAX];
int cmpf(const kkt a,const kkt b)
{
return a.X<b.X;
}
int main()
{
freopen("orase.in","r",stdin);
freopen("orase.out","w",stdout);
scanf("%ld%ld",&m,&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].X>x[i+1].X)
{
a=x[i].X;
x[i].X=x[i+1].X;
x[i+1].X=a;
a=x[i].Y;
x[i].Y=x[i+1].Y;
x[i+1].Y=a;
a=1;
}
} */
sort(x+1,x+n+1,cmpf);
s=/*x[1].X+*/x[1].Y;
mx=-1;
for (i=2;i<=n;i++)
{
if (mx<s+x[i].X-x[i-1].X+x[i].Y)
mx=s+x[i].X-x[i-1].X+x[i].Y;
if (s+x[i].X-x[i-1].X<=x[i].Y)
s=x[i].Y;
else
s+=(x[i].X-x[i-1].X);
}
printf("%ld\n",mx);
return 0;
}