Pagini recente » Cod sursa (job #2298022) | Cod sursa (job #2910767) | Cod sursa (job #1018670) | Cod sursa (job #2124394) | Cod sursa (job #500026)
Cod sursa(job #500026)
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=50005;
struct orase
{
int d,l;
};
int lung,n;
orase v[N];
bool comp(orase a,orase b)
{
return a.d<b.d;
}
void citire()
{
freopen("orase.in","r",stdin);
freopen("orase.out","w",stdout);
scanf("%d%d",&lung,&n);
for (int i=1;i<=n;++i)
scanf("%d%d",&v[i].d,&v[i].l);
sort(v+1,v+n+1,comp);
}
void rez()
{
int u=1,distmax=0,dist;
for (int i=2;i<=n;++i)
{
dist=v[i].l+v[u].l+v[i].d-v[u].d;
if (dist>distmax)
distmax=dist;
if (v[i].l>v[u].l+v[i].d-v[u].d)
u=i;
}
printf("%d\n",distmax);
}
int main()
{
citire();
rez();
return 0;
}