Pagini recente » Cod sursa (job #2747137) | Rating Anghel Horia Petru (Petri) | Cod sursa (job #932138) | Cod sursa (job #1279027) | Cod sursa (job #1365075)
#include <fstream>
#include <algorithm>
#define nmax 1000005
using namespace std;
ifstream f("orase.in");
ofstream g("orase.out");
int n,m,distmax;
struct elem{int x ; int y;};
elem v[nmax];
inline int modul(int x)
{
if (x<0)
return -x;
return x;
}
inline bool compare(const elem &a, const elem &b)
{
return a.x<b.x;
}
int dist(int a,int b)
{
return modul(v[b].x-v[a].x)+v[a].y+v[b].y;
}
int main()
{
int i,j;
f>>m>>n;
for (i=1;i<=n;i++)
f>>v[i].x>>v[i].y;
sort(v+1,v+n+1,compare);
i=1;
for (j=2;j<=n;j++) {
if (dist(i,j)<dist(j-1,j))
i=j-1;
distmax=max(distmax,dist(i,j));
}
g<<distmax;
return 0;
}