Cod sursa(job #1640720)

Utilizator horatiuchevalHoratiu Cheval horatiucheval Data 8 martie 2016 19:00:43
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <fstream>
#include <algorithm>
using namespace std;

struct oras{
    int x;
    int y;
};

oras v[50001];

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

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

    int n, m;
    fin>>m>>n;

    for(int i = 1; i <= n; i++){
        fin>>v[i].x>>v[i].y;
    }

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

    int u = 1, dc, dmax = -1;
    for(int i = 2; i <= n; i++){
        if(v[i-1].y > v[u].y + v[i-1].x - v[u].x)
            u = i - 1;
        dc = v[i].y + v[u].y + v[i].x - v[u].x;
        if(dc >dmax)
            dmax = dc;
    }

    fout<<dmax;

    fin.close();
    fout.close();
    return 0;
}