Pagini recente » Cod sursa (job #2787919) | Cod sursa (job #468215) | Cod sursa (job #55055) | Cod sursa (job #588303) | Cod sursa (job #2814281)
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int main()
{
ifstream fin("orase.in");
ofstream fout("orase.out");
int maxi=0,rez=-INF,maxn;
pair<int,int> a[50001];
int nonnecesar,n;
fin>>nonnecesar>>n;
for(int i=0;i<n;i++)
{
fin>>a[i].first>>a[i].second;
}
sort(a,a+n);
maxn=a[0].second-a[0].first;
for(int i=1;i<n;i++)
{
int x=a[i].second+a[maxi].second+a[i].first-a[maxi].first;
if(x>rez)
{
rez=x;
}
x=a[i].second-a[i].first;
if(x>maxn)
{
maxn=x;
maxi=i;
}
}
fout<<rez;
return 0;
}