Pagini recente » Cod sursa (job #2819934) | Cod sursa (job #3241377) | Cod sursa (job #3193153) | Cod sursa (job #2414837) | Cod sursa (job #2717940)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("orase.in");
ofstream cout("orase.out");
struct city {
int d, h;
bool operator< (const city& x) const {
return d<x.d;
}
}v[50000];
int main() {
int n,maxx,bestuntil;
cin >> n >> n;
for(int i=0; i<n; i++)
cin >> v[i].d >> v[i].h;
sort(v,v+n);
maxx=0;
bestuntil=v[0].h-v[0].d;
for(int i=1; i<n; i++) {
maxx=max(maxx,bestuntil+v[i].h+v[i].d);
bestuntil=max(bestuntil,v[i].h-v[i].d);
}
cout << maxx << '\n';
}