Cod sursa(job #442921)

Utilizator SpiderManSimoiu Robert SpiderMan Data 15 aprilie 2010 17:58:07
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <cstdio>
#include <algorithm>
using namespace std;

#define MAX 50005
#define hg 8192
#define IN "orase.in"
#define OUT "orase.out"

struct vector
{
    int D,L;
}V[MAX],maxi;

struct comp
{
    bool operator () (const vector& lhs , const vector& rhs)
    {
        if (lhs.D == rhs.D)
            return lhs.L < rhs.L;

        return lhs.D < rhs.D;
    }
};

int M, N, i, rez, poz;
char ch[hg];

inline void cit (int &x)
{
    x = 0;
    if (ch[0]=='\0') fread (ch, 1, hg, stdin);
    else while (ch[poz] < '0' || ch[poz] > '9')
            if (++poz == hg)
                fread (ch, 1, hg, stdin), poz = 0;

    while (ch[poz] >= '0' && ch[poz] <= '9')
    {
        x = x * 10 + ch[poz] - '0';
        if (++poz == hg)
            fread (ch, 1, hg, stdin), poz = 0;
    }
}

int main()
{
    freopen(IN,"r",stdin);
    freopen(OUT,"w",stdout);

    cit(M), cit(N);

    for (i = 1; i <= N; i++)
        cit(V[i].D), cit(V[i].L);

    sort(V + 1, V + N + 1, comp());

    maxi.D = V[1].D, maxi.L = V[1].L;

    for (i = 2; i <= N; i++)
    {
        int part = V[i].L + V[i].D + maxi.L - maxi.D;
        if (part > rez) rez = part;
        if (V[i].L - V[i].D > maxi.L - maxi.D) maxi.L = V[i].L, maxi.D = V[i].D;
    }
    printf("%d",rez);
    return 0;
}