Cod sursa(job #1662916)

Utilizator tudoroprisTudor Opris tudoropris Data 25 martie 2016 11:50:17
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<fstream>
#include <algorithm>

using namespace std;

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

int u,i,n,dc,distmax,m,x,y;
const int N=100001;

struct oras
{
    int d,l;
};

oras v[N];

bool cmp(oras x,oras y)
{
    return x.d < y.d;
}

int dist(int x,int y)
{
    int a;
    a = v[x].d - v[y].d + v[y].l + v[x].l;
    return a;
}

int main()
{
    in>>m>>n;
    u=1;
    for(i=1; i<=n; i++)
    {
        in>>v[i].d>>v[i].l;
    }
    sort(v+1,v+n+1,cmp);
    for(i=2; i<=n; i++)
    {
        if(dist(i,(i-1))>dist(i,u))
            u=i-1;
        dc=dist(i,u);
        if(dc>distmax)
            distmax=dc;
    }
    out<<distmax;
}