Cod sursa(job #3310414)

Utilizator Maria_MihailescuMihailescu Maria Maria_Mihailescu Data 13 septembrie 2025 17:18:55
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

const int NMAX = 5e4;
 struct oras{
    int d;
    int l;
 };

 bool cmp(oras a, oras b){
    return a.d < b.d;
    return a.l < b.l;
 }
oras v[NMAX + 1];

int main(){
    int n, m;
    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 dmax = 0;
    int cmb = v[1].d - v[1].l;
    for (int i = 1; i <= n; i++){
        int d = (v[i].d + v[i].l) - cmb;
        if (d > dmax)
        dmax = d;
        if (v[i].d - v[i].l < cmb)
        cmb = v[i].d - v[i].l;
    }
    fout << dmax;
    return 0;
}