Cod sursa(job #2815697)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 10 decembrie 2021 09:19:50
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("orase.in");
ofstream cout("orase.out");
int n,m,x,y;
const int N=50005;
struct oras
{
    int d,l;
} v[N];
bool cmp(oras a,oras b)
{
    if(a.d!=b.d)
        return a.d<b.d;
}
int main()
{
    cin >> m >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> v[i].d >> v[i].l;

    }
    sort(v + 1, v + n + 1, cmp);

//    for (int i = 1; i <= n; ++i)
//        cout << v[i].d << ' ';
//    cout<<'\n';
//    for (int i = 1; i <= n; ++i)
//        cout << v[i].l << ' ';
    int dc,dmax;
    dc=dmax=v[2].d-v[1].d+v[2].l+v[1].l;
    for (int i = 3; i <= n; ++i)
    {
        dc+=v[i].d-v[i-1].d+v[i].l-v[i-1].l;
        dc=max(dc,v[i].d-v[i-1].d+v[i].l+v[i-1].l);
        dmax=max(dc,dmax);
    }
    cout << dmax << '\n';
}