Pagini recente » Cod sursa (job #341413) | Cod sursa (job #1913196) | Cod sursa (job #283723) | Cod sursa (job #2096093) | Cod sursa (job #2669627)
#include <fstream>
#include <algorithm>
#include <iostream>
using namespace std;
const int MAX_LENGTH = 50002;
struct City{
int position, length;
};
bool sortCity(City first, City second){
if (first.position < second.position){
return true;
}else if (first.position == second.position && first.length < second.length){
return true;
}
return false;
}
int main (void){
ifstream fin ("orase.in");
int length, toIgnore;
fin>>toIgnore>>length;
City city[MAX_LENGTH];
for (int i=1; i<=length; i++){
fin>>city[i].position>>city[i].length;
}
fin.close();
sort(city+1, city+length+1, sortCity);
int maxPath = city[1].length;
int maxPathIndex = 1;
int maxim = 0;
for (int i=2; i<=length; i++){
int aux = maxPath + city[i].position - city[maxPathIndex].position + city[i].length;
if (aux > maxim)
maxim = aux;
if (city[i].length > (maxPath + city[i].position - city[maxPathIndex].position)){
maxPath = city[i].length;
maxPathIndex = i;
}
}
ofstream fout("orase.out");
fout<<maxim<<"\n";
fout.close();
return 0;
}