Pagini recente » Cod sursa (job #2846514) | Cod sursa (job #1585964) | Cod sursa (job #166695) | Cod sursa (job #1519489) | Cod sursa (job #2232089)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("orase.in");
ofstream out("orase.out");
int n,m,d,r;
pair <int,int> p[50001];
int main()
{ in>>m>>n;
for(int i=1;i<=n;i++)
in>>p[i].first>>p[i].second;
sort(p+1,p+n+1);
d=r=p[2].first-p[1].first+p[1].second+p[2].second;
for(int i=3;i<=n;i++)
{ d=max(d-p[i-1].first+p[i].first+p[i].second-p[i-1].second,p[i-1].second+p[i].second+p[i].first-p[i-1].first);
r=max(d,r);
}
out<<r;
in.close();
out.close();
return 0;
}