Cod sursa(job #3324923)

Utilizator nopreanOprean Natasha noprean Data 24 noiembrie 2025 09:33:11
Problema Orase Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("orase.in");
ofstream fout("orase.out");
int m,n;
struct strada{
    int d,l;
}A[50001];
bool ord(strada a, strada b)
{
    if(a.d<b.d)
        return true;
    if(a.d==b.d && a.l>b.l)
        return true;
    return false;
}
int main()
{
    fin>>m>>n;
    for(int i=1;i<=n;i++)
        fin>>A[i].d>>A[i].l;
    sort(A+1,A+n+1,ord);
    int distMax=0;
    int drumMax=A[1].l;
    int poz=1;
    for(int i=2;i<=n;i++)
    {
        //fout<< A[poz].l+A[i].l+(A[i].d-A[poz].d)<<" ";
        if(A[poz].l+A[i].l+(A[i].d-A[poz].d)>distMax)
        {
            distMax=A[poz].l+A[i].l+(A[i].d-A[poz].d);
        }
        if(A[i].l>A[poz].l)
            poz=i;
    }
    fout<<distMax;
    return 0;
}