Cod sursa(job #797324)

Utilizator alex_unixPetenchea Alexandru alex_unix Data 13 octombrie 2012 20:10:54
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb

#include <fstream>
#include <utility>
#include <algorithm>

const int MAX_SIZE(50000);

std::pair<int,int> streets [MAX_SIZE];

int main (void)
{
	std::ifstream input("orase.in");
	int m, n;
	input >> m >> n;
	std::pair<int, int> *iterator(streets), *end(streets + n);
	while (iterator < end)
	{
		input >> iterator->first >> iterator->second;
		++iterator;
	}
	input.close();
	std::sort(streets,end);
	int max(streets->second - streets->first), best(0);
	for (iterator = streets + 1 ; iterator < end ; ++iterator)
	{
		if (iterator->second + iterator->first + max > best)
			best = iterator->second + iterator->first + max;
		if (iterator->second - iterator->first > max)
			max = iterator->second - iterator->first;
	}
	std::ofstream output("orase.out");
	output << best << '\n';
	output.close();
	return 0;
}