Cod sursa(job #791554)

Utilizator classic_gamesofia nitoi classic_game Data 24 septembrie 2012 16:16:36
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <algorithm>

using namespace std;

int m,n,dmax,dc;

struct punct
{
    int l,d;
};

punct x[1000001];

bool cmp(punct a,punct b)
{
    if (a.d<b.d) return true;
    return false;
}

int main()
{
    int i,j;
    ifstream f("orase.in");
    ofstream g("orase.out");
    f>>n>>m;
    for (i=1;i<=m;i++)
        f>>x[i].d>>x[i].l;
    sort(&x[1],&x[m+1],cmp);
    int u=1;
    for (i=2;i<=m;i++)
    {
        dc=x[i].l+x[u].l+x[i].d-x[u].d;
        if (dc>dmax) dmax=dc;
        if (x[u].l+x[i].d-x[u].d<x[i].l)
            u=i;
    }
    g<<dmax;
    return 0;
}