Cod sursa(job #1565198)

Utilizator tziplea_stefanTiplea Stefan tziplea_stefan Data 10 ianuarie 2016 15:10:34
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <algorithm>
#define ValN 50005

using namespace std;

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

int N, i, M;
int mx, mn;

struct oras
{
    int d;
    int l;
};

oras v[ValN];

bool cmp(oras a, oras b)
{
    if (a.d<b.d)
      return true;
    else
      return false;
}

int main()
{
    fin >> M >> N;
    for (i=1; i<=N; i++)
      fin >> v[i].d >> v[i].l;
    sort(v+1, v+N+1, cmp);
    mn=1;
    for (i=1; i<=N; i++)
    {
        if (v[i].d-v[mn].d+v[i].l+v[mn].l>mx)
          mx=v[i].d-v[mn].d+v[i].l+v[mn].l;
        if (v[i].l-v[mn].l>v[i].d-v[mn].d)
          mn=i;
    }
    fout << mx << '\n';
    fin.close();
    fout.close();
    return 0;
}