Pagini recente » Cod sursa (job #2271539) | Cod sursa (job #2056437) | Cod sursa (job #2044848) | Borderou de evaluare (job #156986) | Cod sursa (job #2815614)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin ("orase.in");
ofstream cout ("orase.out");
struct ura
{
int d,l;
};
ura v[50010];
bool cmp(ura a,ura b)
{
if (a.d<b.d)
return true;
else
return false;
}
int main()
{
int n,m,i,maxx,maxim,x,p;
cin>>m>>n;
for (i=1; i<=n; i++)
cin>>v[i].d>>v[i].l;
sort (v+1,v+n+1,cmp);
maxim=v[1].l-v[1].d;
p=1;
maxx=-1000000;
for (i=2; i<=n; i++)
{
x=v[p].l+v[i].l+v[i].d-v[p].d;
maxx=max(maxx,x);
x=v[i].l-v[i].d;
if (x>maxim)
{
maxim=x;
p=i;
}
}
cout<<maxx;
return 0;
}