Cod sursa(job #976288)

Utilizator manutrutaEmanuel Truta manutruta Data 22 iulie 2013 22:47:29
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

ifstream f("orase.in");
ofstream g("orase.out");

struct oras {
    int d, l;
};

inline bool cmp(oras a, oras b) {
    return a.d < b.d;
}

int n, m;
oras orase[50005];
int dmax;
int s, mx;

int main()
{
    f >> m >> n;

    for (int i = 1; i <= n; i++) {
        f >> orase[i].d >> orase[i].l;
    }

    sort(orase + 1, orase + n + 1, cmp);

    for (int i = 1; i <= n; i++)
    {
        if (s < mx + orase[i].d + orase[i].l)
            s = mx + orase[i].d + orase[i].l;
        if (mx < orase[i].l - orase[i].d)
            mx = orase[i].l - orase[i].d;
    }

    g << s;

    return 0;
}