Cod sursa(job #829394)

Utilizator SmarandaMaria Pandele Smaranda Data 5 decembrie 2012 12:01:04
Problema Orase Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
#include <cstdio>
#include <algorithm>
#define NMAX 50020

using namespace std;

struct City {
    long x , y;
    void make (const long &xx , const long &yy) {
        x = xx;
        y = yy;
    }
};

class MyComp {
    public :
        bool operator () (const City &A , const City &B) {
            return (A.x < B.x);
        }
};

City O [NMAX];

void Read (long &N , long &M) {
    long x , y;
    scanf ("%ld%ld" , &N , &M);
    for (long i = 1 ; i <= N ; i ++) {
        scanf ("%ld%ld" , &x , &y);
        O [i].make (x , y);
    }
    O [++N].make (M , 0);
}

long dist (const long &a , const long &b) {
    return O [b].x - O [a].x + O [a].y + O [b].y;
}

void Solve (const long &N , const long &M) {
    long i , u , d1 , d2 , max = -1;

    sort (O + 1 , O + 1 + N , MyComp ());

    u = 1;
    for (i = 2 ; i <= N ; i ++) {
        d1 = dist (u , i);
        d2 = dist (i - 1 , i);
        if (d2 > d1)
            u = i - 1;
        if (d1 > max) max = d1;
        if (d2 > max) max = d2;
    }

    printf ("%ld\n" , max);
}

int main () {
    long N , M;

    freopen ("orase.in" , "r" , stdin);
    freopen ("orase.out" , "w" , stdout);

    Read (N , M);
    Solve (N , M);
    return 0;
}