Cod sursa(job #3137521)

Utilizator AlexSerban21Serban Alexandru AlexSerban21 Data 13 iunie 2023 10:12:50
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("orase.in");
ofstream fout ("orase.out");
int m,n,maxc,dmax,i,j;
struct el
{
    int d,l;
};
el v[50001];
int cmp (const el &a,const el &b)
{
    if (a.d==b.d)
        return a.l<b.l;
    return a.d<b.d;
}
int main()
{
    fin>>m>>n;
    for (i=1; i<=n; i++)
        fin>>v[i].d>>v[i].l;
    sort (v+1,v+n+1,cmp);
    dmax=v[1].l-v[1].d;
    j=1;
    for (i=2; i<=n; i++)
    {
        if (v[i].d+v[i].l+dmax>maxc)
            maxc=v[i].d+v[i].l+dmax;
        if (v[i].l-v[i].d>dmax)
        {
            dmax=v[i].l-v[i].d;
            j=i;
        }
    }
    fout<<maxc;
    return 0;
}