Pagini recente » Cod sursa (job #1083156) | Cod sursa (job #1940403) | Cod sursa (job #760329) | Cod sursa (job #405166) | Cod sursa (job #843262)
Cod sursa(job #843262)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("orase.in");
ofstream g("orase.out");
long n,m,sum,max1,i;
struct st
{
int d,l;
};
st dp[50002];
int comp(st a,st b)
{
return (a.d<b.d);
}
int main()
{
f>>m>>n;
for(i=1;i<=n;i++)
f>>dp[i].d>>dp[i].l;
sort(dp+1,dp+n+1,comp);
max1=dp[1].l-dp[1].d;
for(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;
return 0;
}