Cod sursa(job #629077)

Utilizator thea35Mihai Ana thea35 Data 2 noiembrie 2011 17:02:30
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <algorithm>

using namespace std;

const int DMax=1000001;

struct punct
    {
        int d,l;
    };
punct v[DMax];

bool cmp (punct x, punct y)
{
    return x.d<y.d;
}

int main()
{
    int n, m, departe=1, dmax=0, i, dc;
    ifstream in("orase.in");
    ofstream out("orase.out");




    in>>m>>n;

    for(i=1; i<=n; i++)
    {
        in>>v[i].d>>v[i].l;
    }



    sort(&v[1],&v[n+1],cmp);


    for(i=2; i<=n; i++)
    {
        dc=v[i].d-v[departe].d+v[i].l+v[departe].l;
        if(dc>dmax)
            dmax=dc;
        if(v[i].l>v[departe].l+v[i].d-v[departe].d)
            departe=i;
    }

    out<<dmax;
    return 0;
}