Pagini recente » Cod sursa (job #2147913) | Cod sursa (job #1763893) | Cod sursa (job #1586026) | Cod sursa (job #677051) | Cod sursa (job #1343183)
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream cin("orase.in");
ofstream cout("orase.out");
typedef struct pc
{
int x, y;
} ;
int n, i, m, j, k, r, best;
pc a[50005];
bool cmp(const pc &a, const pc &b)
{
return a.x<b.x;
}
int main()
{
cin>>m>>n;
a[1].x=1;
for
(i=1; i<=n; ++i)
cin>>a[i].x>>a[i].y;
sort(a+1, a+n+1, cmp);
best=1;
int sol=0;
for (i=2; i<=n; ++i)
if (a[i].x-a[best].x+a[i].y+a[best].y < a[i].x-a[i-1].x+a[i].y+a[i-1].y)
sol=max(a[i].x-a[i-1].x+a[i].y+a[i-1].y, sol),
best=i-1;
else
sol=max(a[i].x-a[best].x+a[i].y+a[best].y, sol);
cout<<sol;
return 0;
}