Cod sursa(job #1676020)

Utilizator alittlezzCazaciuc Valentin alittlezz Data 5 aprilie 2016 18:07:39
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;

struct city{
  int d,l;
}v[50005];

bool comp(city c1, city c2){
    return c1.d < c2.d;
}
 
int main()
{
    int i,n,m;
    freopen("orase.in", "r", stdin);
    freopen("orase.out", "w", stdout);
    scanf("%d %d",&m,&n);
    for(i = 1;i <= n;i++){
        scanf("%d %d",&v[i].d,&v[i].l);
    }
    sort(v+1, v+n+1, comp);
    int st,dr;
    int sol = 0;
    for(st = 1,dr = 2;dr <= n;dr++){
        sol = max(sol, v[dr].d - v[st].d + v[dr].l + v[st].l);
        if(v[dr].l > v[dr].d - v[st].d + v[st].l){
            st = dr;
        }
    }
    printf("%d",sol);
    return 0;
}