Pagini recente » Cod sursa (job #486923) | Cod sursa (job #2793613) | Cod sursa (job #3160128) | Cod sursa (job #407387) | Cod sursa (job #912113)
Cod sursa(job #912113)
#include <stdio.h>
#include <algorithm>
using namespace std;
struct nod {
int x,y;
};
bool comp(nod a, nod b) {
if(a.x < b.x) return 1;
else if(a.x == b.x && a.y < b.y) return 1;
return 0;
}
nod a[51000];
int main()
{
int i,n,m,max,maxdist,pozd;
freopen("orase.in","r",stdin);
freopen("orase.out","w",stdout);
scanf("%d %d",&n,&m);
for(i=0;i<m;i++)
scanf("%d %d",&a[i].x,&a[i].y);
sort( a, a+m, comp);
max=a[0].y; pozd=a[0].x; maxdist=0;
for(i=1; i<m; i++)
{
if(max + a[i].x-pozd + a[i].y > maxdist) maxdist = max + a[i].x - pozd + a[i].y ;
if(a[i].y > max + a[i].x-pozd) {
max= a[i].y;
pozd= a[i].x;
}
}
printf("%d\n",maxdist);
return 0;
}