Pagini recente » Cod sursa (job #1233316) | Cod sursa (job #2713562) | Cod sursa (job #135582) | Cod sursa (job #2365727) | Cod sursa (job #797324)
Cod sursa(job #797324)
#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;
}