Cod sursa(job #1309717)

Utilizator dr_personalityEftime Andrei Horatiu dr_personality Data 5 ianuarie 2015 23:07:18
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream in("orase.in");
ofstream out("orase.out");

struct point{
	int d, l;
};

const int nmax = 50006;
int n, m, rasp, dmax, lmax;
point v[nmax];

int compar(point a, point b)
{
	return a.d<b.d;
}

int main(){
	int player_unu=0;

	in>>m>>n;
	for(int i = 1; i<=n; i++)
		in>>v[i].d>>v[i].l;

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

	dmax = v[1].d;

	for(int i = 1; i<=n; i++)
	{
		if(v[i].l + v[i].d - dmax + lmax>rasp)
		{
			rasp = v[i].l + v[i].d - dmax + lmax;
		}

		if(v[i].d - dmax + lmax<v[i].l)
		{
			dmax = v[i].d;
			lmax = v[i].l;
		}
	}

	out<<rasp<<'\n';

	return player_unu;
}