Cod sursa(job #486268)

Utilizator ChallengeMurtaza Alexandru Challenge Data 20 septembrie 2010 22:14:03
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;

const char InFile[]="orase.in";
const char OutFile[]="orase.out";

ifstream fin(InFile);
ofstream fout(OutFile);

struct e
{
	e(int d, int l):D(d),L(l){}
	int D,L;
};

bool ecmp(e a, e b)
{
	if(a.D!=b.D)
	{
		return a.D<b.D;
	}
	else
	{
		return a.L<b.L;
	}
}

int n,m,best,sol,d,l;
vector<e> v;

int main()
{
	fin>>m>>n;
	for(register int i=0;i<n;++i)
	{
		fin>>d>>l;
		v.push_back(e(d,l));
	}
	fin.close();

	sort(v.begin(),v.end(),ecmp);

	for(register int i=0;i<n;++i)
	{
		sol=max(sol,best+v[i].D+v[i].L);
		best=max(best,v[i].L-v[i].D);
	}

	fout<<sol;
	fout.close();
	return 0;
}