Cod sursa(job #476713)

Utilizator blasterzMircea Dima blasterz Data 12 august 2010 11:01:24
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <cstdio>
#include <algorithm>

using namespace std;

struct nod
{
	int d, l;
};

struct cmp
{
	bool operator () (const nod &a, const nod &b) const
	{
		if (a.d < b.d) 
			return true;
		return false;
	}
};

nod a[50001];
int n, m;

int main ()
{
	freopen ("orase.in", "r", stdin);
	freopen ("orase.out", "w", stdout);

	scanf ("%d %d\n", &m, &n);
	int i;
	for (i = 1; i <= n; ++i)
		scanf ("%d %d\n", &a[i].d, &a[i].l);

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

	int sol = 0, p = 0;

	for (i = 1; i <= n; ++i)
	{
		sol = max (sol, p + a[i].l);
		p = max (p, a[i].l);
		if (i < n)
			p += a[i + 1].d - a[i].d;
	}

	printf ("%d\n", sol);
	return 0;
}