Cod sursa(job #998714)

Utilizator sleepaholicNeculaescu Theodor sleepaholic Data 17 septembrie 2013 21:15:26
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("orase.in");
ofstream g("orase.out");

struct oras{ int d, l; }a[50005];
int n, m, sum, bestsum, j=1;

int asa(oras x, oras y) { return x.d<y.d; }

int main()
{
    f>>m>>n;
    for(int i=1; i<=n; ++i) f>>a[i].d>>a[i].l;
    sort(a+1, a+1+n, asa);

    for(int i=2; i<=n; ++i)
    {
        sum=a[i].l+a[i].d+a[j].l-a[j].d;
        if(sum>bestsum) bestsum=sum;
        if(a[i].d+a[j].l < a[i].l+a[j].d) j=i;
    }
    g<<bestsum<<'\n';
    return 0;
}