Pagini recente » Cod sursa (job #279190) | Cod sursa (job #1096111) | Cod sursa (job #1612404) | Cod sursa (job #585729) | Cod sursa (job #1662916)
#include<fstream>
#include <algorithm>
using namespace std;
ifstream in("orase.in");
ofstream out("orase.out");
int u,i,n,dc,distmax,m,x,y;
const int N=100001;
struct oras
{
int d,l;
};
oras v[N];
bool cmp(oras x,oras y)
{
return x.d < y.d;
}
int dist(int x,int y)
{
int a;
a = v[x].d - v[y].d + v[y].l + v[x].l;
return a;
}
int main()
{
in>>m>>n;
u=1;
for(i=1; i<=n; i++)
{
in>>v[i].d>>v[i].l;
}
sort(v+1,v+n+1,cmp);
for(i=2; i<=n; i++)
{
if(dist(i,(i-1))>dist(i,u))
u=i-1;
dc=dist(i,u);
if(dc>distmax)
distmax=dc;
}
out<<distmax;
}