Cod sursa(job #68216)

Utilizator DastasIonescu Vlad Dastas Data 27 iunie 2007 01:44:09
Problema Orase Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <cstdio>
#include <cstdlib>

#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 max, pozmax;

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);
        if ( a[i].l > max )
            max = a[i].l, pozmax = i;
    }
}


int main()
{
    read();

    for ( int i = 0; i < n; ++i )
        if ( i != pozmax )
            if ( a[i].l + max + abs(a[i].d - a[pozmax].d) > rez )
                rez = a[i].l + max + abs(a[i].d - a[pozmax].d);

    fprintf(out, "%d\n", rez);

    return 0;
}