Cod sursa(job #854923)

Utilizator TheShadowsAlexandru Cristian TheShadows Data 14 ianuarie 2013 12:59:18
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<fstream>
#include<algorithm>
using namespace std;
const int LIM = 50001;
struct oras{
    int x, l;
}v[LIM];
bool compare(oras a, oras b){
    return a.x<b.x;
}
int u=1, m, n, maxl=0;
int main(){
    ifstream in("orase.in");
    ofstream out("orase.out");
    in>>m>>n;
    for(int i=1; i<=n; i++){
        in>>v[i].x>>v[i].l;
    }
    sort(v+1, v+n+1, compare);
    int current;
    for(int i=2; i<=n; i++){
        current=v[u].l+(v[i].x-v[u].x);
        if(current+v[i].l>maxl)
            maxl=current+v[i].l;
        if(current<v[i].l) u=i;
    }
    out<<maxl<<"\n";
    return 0;
}