Cod sursa(job #1344325)

Utilizator sterymanSterian Cosmin Cristian steryman Data 16 februarie 2015 17:16:26
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <algorithm>

struct oras{
    int d,l;
};

using namespace std;

oras v[50001];

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

int main()
{
    ifstream f("orase.in");
    ofstream g("orase.out");

    int n, i, m, u, dmax=-2000000000;
    f>>m>>n;
    for(i=1;i<=n;i++)
        f>>v[i].d>>v[i].l;
    sort(v+1, v+n+1, cmp);
    u=1;
    for(i=2;i<=n;i++)
    {
        if(v[i-1].l>v[u].l+v[i-1].d-v[u].d)
            u=i-1;
        if(v[i].d-v[u].d+v[i].l+v[u].l>dmax)
            dmax=v[i].d-v[u].d+v[i].l+v[u].l;
    }
    g<<dmax;
}