Pagini recente » Cod sursa (job #556683) | Cod sursa (job #617911) | Cod sursa (job #1875879) | Cod sursa (job #1057630) | Cod sursa (job #629660)
Cod sursa(job #629660)
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
struct oras {
long d,l;
};
inline bool cmp (const oras a, const oras b)
{
if(a.d==b.d)
return a.l>b.l;
else return a.d<b.d;
}
int main ()
{
long n,i,j,m,c,ca,l,max;
oras v[50001];
ifstream f("orase.in");
ofstream g("orase.out");
f>>m>>n;
for(i=1;i<=n;i++)
f>>v[i].d>>v[i].l;
f.close();
sort(v+1,v+n+1,cmp);
c=v[1].l;
ca=v[1].d;
max=c;
for(i=2;i<=n;i++) {
l=c+v[i].d-ca;
if((v[i].l+l)>max)
max=v[i].l+l;
if(v[i].l>l) {
c=v[i].l;
ca=v[i].d;
}
}
g<<max;
g.close();
return 0;
}