Pagini recente » Cod sursa (job #478303) | Cod sursa (job #3270387) | Cod sursa (job #2347987) | Cod sursa (job #1487407) | Cod sursa (job #1466388)
#include <cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
FILE *f=fopen("orase.in", "r");
FILE *g=fopen("orase.out", "w");
struct date{
int d, l;
};
vector <date> v;
bool cmp(date a, date b){
return (a.d<b.d);
}
int main()
{
int n, maxx=-500, maxi=-500, m;
date aux, bux;
fscanf(f, "%d%d", &m, &n);
for(int i=1; i<=n; ++i){
fscanf(f, "%d%d", &aux.d, &aux.l);
v.push_back(aux);
}
sort(v.begin(), v.end(), cmp);
aux=v[0];
maxx=abs(aux.l-aux.d);
for(int i=1; i<n; ++i){
aux=v[i];
maxi=max(maxi, maxx+aux.d+aux.l);
maxx=max(maxx, abs(aux.d-aux.l));
}
fprintf(g, "%d", maxi);
return 0;
}