Cod sursa(job #1365075)

Utilizator badea_adi1999Badea Adrian Catalin badea_adi1999 Data 28 februarie 2015 00:47:04
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#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;
}