Cod sursa(job #2590581)

Utilizator r00t_Roman Remus r00t_ Data 28 martie 2020 14:08:21
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>


using namespace std;

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

vector<tuple<int, int>>vp;

int main()
{
    int n, m;
    fin >> m >> n;
    for (int i = 0; i < n; i++)
    {
        int d, L;
        fin >> d >> L;
        vp.push_back({ d,L });
    }


    sort(vp.begin(), vp.end());

    auto lst = vp[0];
    int dstmax = 0;

    for (int i = 1; i < n; i++)
    {
        int d1,l1,d2, l2;
        tie(d1, l1) = lst;
        tie(d2, l2) = vp[i];
        
        int dst = d2 - d1 + l1 + l2;
        if (dst > dstmax)
        {
            dstmax = dst;
        }

        if (l1 + d2 - d1 < l2) // daca se indeplineste, gasim o strada mai buna decat cea de dinainte
            lst = vp[i];       
    }

    fout << dstmax;




    return 0;
}