Pagini recente » Cod sursa (job #1700847) | Cod sursa (job #1257589) | Cod sursa (job #1462452) | Cod sursa (job #1602691) | Cod sursa (job #991146)
Cod sursa(job #991146)
#include<fstream>
#include<algorithm>
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;
}