Pagini recente » Cod sursa (job #2541284) | Cod sursa (job #252448) | Cod sursa (job #1457785) | Cod sursa (job #2615069) | Cod sursa (job #991145)
Cod sursa(job #991145)
#include<fstream>
#include<algorithm>
#define Nmax 50001
using namespace std;
ifstream f("orase.in"); ofstream g("orase.out");
struct oras {int d,l;} v[50001];
int cmp (oras a,oras b) {return a.d<=b.d;}
int main()
{ int n,m,i;
f>>m>>n;
for(i=1;i<=n;++i) f>>v[i].d>>v[i].l;
sort(v+1,v+n+1,cmp);
int dist,distmax=0,dif,difmax=v[1].l-v[1].d;
for(i=2;i<=n;++i)
{ dist=v[i].l+v[i].d+difmax;
if(dist>distmax) distmax=dist;
dif=v[i].l-v[i].d;
if(dif>difmax) difmax=dif;
}
g<<distmax<<"\n"; g.close(); return 0;
}