Pagini recente » Cod sursa (job #1877964) | Cod sursa (job #1463150) | Cod sursa (job #2191489) | Cod sursa (job #2010845) | Cod sursa (job #473399)
Cod sursa(job #473399)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("orase.in");
ofstream g("orase.out");
long N,M,sum,max1;
struct dist { int d,l; }dp[50002];
bool cmp(dist i,dist j) { return (i.d<j.d); }
int main()
{ f>>M>>N;
for(int i=1;i<=N;i++)
f>>dp[i].d>>dp[i].l;
sort(dp+1,dp+N+1,cmp);
max1=dp[1].l-dp[1].d;
for(int i=2;i<=N;i++)
{ if(sum<dp[i].l+dp[i].d+max1)
sum=dp[i].l+dp[i].d+max1;
if(max1<dp[i].l-dp[i].d)
max1=dp[i].l-dp[i].d;
}
g<<sum;
f.close();
g.close();
return 0;
}