Cod sursa(job #68477)

Utilizator DastasIonescu Vlad Dastas Data 28 iunie 2007 01:36:32
Problema Orase Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <cstdio>
#include <cstdlib>
#include <algorithm>

#define nmax 50000

FILE *in = fopen("orase.in","r"), *out = fopen("orase.out","w");

struct orase
{
    int d, l;
};

int m, n;
orase a[nmax];

int rez;

void read()
{
    fscanf(in, "%d %d", &m, &n);

    for ( int i = 0; i < n; ++i )
        fscanf(in, "%d %d", &a[i].d, &a[i].l);
}

bool operator<(const orase &x, const orase &y)
{
    return x.d < y.d;
}

int main()
{
    read();

    std::sort(a, a+n);

    int comp = 0;

    for ( int i = 1; i < n; ++i )
    {
        if ( a[i].l + a[comp].l + abs(a[comp].d-a[i].d) > rez )
            rez = a[i].l + a[comp].l + abs(a[comp].d-a[i].d);

        if ( a[comp].l < a[i].l )
            comp = i;
    }
    fprintf(out, "%d\n", rez);

    return 0;
}