Pagini recente » Cod sursa (job #854729) | Cod sursa (job #284381) | Rating Stefan Sigartau (StefanS007) | Cod sursa (job #1990037) | Cod sursa (job #329832)
Cod sursa(job #329832)
#include<fstream>
#include<algorithm>
#define MaxN 50005
using namespace std;
ifstream fin("orase.in");
ofstream fout("orase.out");
struct casa {
int l,d;
};
casa v[MaxN];
int i,j=1,n,m,D,dis;
int cmp(casa a, casa b)
{ return a.d<b.d;}
int main()
{ fin>>m>>n;
for(i=1;i<=n;i++) fin>>v[i].d>>v[i].l;
sort(v+1,v+1+n,cmp);
dis=v[1].l-v[1].d;
for(i=2;i<=n;i++)
{ if(v[i].l-v[i].d>dis) j=i;
else D=v[i].l+v[i].d+v[j].l-v[j].d;
}
/*D=v[j+1].l+v[j+1].d+v[j].l-v[j].d;
for(i=j+2;i<=n;i++)
if(v[i].l+v[i].d+v[j].l-v[j].d>D) D=v[i].l+v[i].d+v[j].l-v[j].d;*/
fout<<D<<'\n';
return 0;
}