Cod sursa(job #3376643)

Utilizator bobitzaxddCucos Bogdan bobitzaxdd Data 18 noiembrie 2026 19:03:03
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    ifstream fin("orase.in");
    ofstream fout("orase.out");
    int M, N;
    fin >> M >> N;
    vector<pair<int,int>> v(N);
    for (auto &p : v) fin >> p.first >> p.second;
    sort(v.begin(), v.end());

    long long ans = 0, best = -4e18; 
    for (auto &[d, l] : v)
    {
        if (best > -4e18) ans = max(ans, best + d + l);
        best = max(best, (long long)l - d);
    }
    fout << ans;
}