Cod sursa(job #3310378)

Utilizator coldsh1tANdrei coldsh1t Data 13 septembrie 2025 11:48:39
Problema Orase Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("orase.in");
ofstream fout("orase.out");

struct q
{
    int d, l;
};

q v[50005];

int cmp(q a, q b)
{
    if(a.d>b.d)
        return true;
    return false;
}

int main()
{
    int m, n, ans=-1000000;
    fin>>m>>n;

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

    sort(v+1, v+n+1, cmp);


    int j=1;

    for(int i=1;i<=n;i++)
    {
        if(v[i].d+v[i].l-(v[j].d-v[j].l)>ans)
        {
            ans=v[i].d+v[i].l-(v[j].d-v[j].l);
        }
        if((v[j].d-v[j].l)>v[i].d+v[i].l)
        {
            j=i+1;
        }
    }

    fout<<ans;


    return 0;
}