Cod sursa(job #417890)

Utilizator pykhNeagoe Alexandru pykh Data 14 martie 2010 23:48:15
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<algorithm>
using namespace std;
const char in[]="orase.in", out[]="orase.out";
struct LD{long d, l;}v[50005];

struct cmp{
	bool operator()(const LD &a, const LD &b)
	{
		return a.d < b.d;
	}
};

int main()
	{
		freopen(in,"r",stdin);
		freopen(out,"w",stdout);
		long n, m, i, maxj = 0, maxi = 0;
		scanf("%ld%ld", &m, &n);
		for(i = 1 ; i <= n ; ++i)
			scanf("%d%d", &v[i].d, &v[i].l);
		sort(v + 1 , v + n + 1 ,  cmp());
		for(i = 1 ; i <= n; ++i)
			{
			if( v[ i - 1 ].l - v[ i - 1 ].d > maxj )maxj = v[ i - 1 ].l - v[ i - 1 ].d;
			if( v[ i ].l + v[ i ].d + maxj > maxi ) maxi = v[ i ].l + v[ i ].d + maxj;
		}
		printf("%ld", maxi);
		return 0;
}