Pagini recente » Cod sursa (job #908255) | Cod sursa (job #2368642) | Cod sursa (job #352540) | Cod sursa (job #2234987) | Cod sursa (job #1589784)
#include <cstdio>
#include<algorithm>
#define MAX 50000
using namespace std;
struct orase{long long x, y;};
orase v[MAX+2];
long long best[MAX+2], maxi;
inline long long maxim(long long a, long long b)
{
if(a>b)
return a;
return b;
}
bool cresc(orase a, orase b)
{
if(a.x<b.x)
return true;
if(a.x==b.x)
return (a.y<b.y);
return false;
}
inline long long dist(int i, int j){
return v[i].y+v[j].y+v[j].x-v[i].x;
}
int main()
{
freopen("orase.in", "r", stdin);
freopen("orase.out", "w", stdout);
int n, i, m;
scanf("%d%d", &n, &m);
for(i=1;i<=n;i++)
scanf("%lld%lld", &v[i].x, &v[i].y);
sort(v+1, v+n+1, cresc);
best[1]=0;
best[2]=dist(1, 2);
maxi=best[2];
for(i=3;i<=n;i++)
{
best[i]=maxim(best[i-1]-v[i-1].y+v[i].y+v[i].x-v[i-1].x, dist(i-1, i));
maxi=maxim(maxi, best[i]);
}
printf("%lld", maxi);
return 0;
}