Cod sursa(job #531032)

Utilizator kyky_papoiPapoi Cecilia kyky_papoi Data 8 februarie 2011 20:18:37
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;


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

#define INF 0x3f3f3f3f

int l, n,d;
vector<pair <int, int > > v;

void Read();
void Do();
void Write();



int main()
{
	Read();
	Do();
	Write();
	
	fin.close();
	fout.close();
	
	return 0;
}

void Read()
{
	int x, y;
	fin >> l >> n;
	while (fin >> x >> y )
	{
		v.push_back(make_pair(x,y));
	}
}

void Do()
{
	sort( v.begin(), v.end() );
	int x;
	x = v[0].second - v[0].first;
	d = -INF;
	for ( int i = 1; i < n; ++i )
	{
		d = max(d, v[i].second+v[i].first + x);
		x = max(v[i].second-v[i].first,x);
	}
}

void Write()
{
	fout << d;
}