Cod sursa(job #1343183)

Utilizator LycrsTrifan Tamara Lycrs Data 14 februarie 2015 23:11:27
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream cin("orase.in");
ofstream cout("orase.out");
 
typedef struct pc
{
	int x, y;
 } ;
 
int n, i, m, j, k, r, best;
pc a[50005];

bool cmp(const pc &a, const pc &b)
{
	return a.x<b.x;
}
 
int main()
{
	
	cin>>m>>n;
	a[1].x=1;
	for
	(i=1; i<=n; ++i)
		cin>>a[i].x>>a[i].y;
		
	sort(a+1, a+n+1, cmp);
		
	best=1;
	int sol=0;
	
	
	for (i=2; i<=n; ++i)
		if (a[i].x-a[best].x+a[i].y+a[best].y < a[i].x-a[i-1].x+a[i].y+a[i-1].y)
			sol=max(a[i].x-a[i-1].x+a[i].y+a[i-1].y, sol),
			best=i-1;
			else 
			sol=max(a[i].x-a[best].x+a[i].y+a[best].y, sol);
	

	cout<<sol;
	
    return 0;
}