Pagini recente » Cod sursa (job #2898364) | Cod sursa (job #1973305) | Cod sursa (job #2252706) | Cod sursa (job #2821999) | Cod sursa (job #2670225)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("orase.in");
ofstream fout("orase.out");
const int N=50000;
struct oras
{
int d,l;
};
bool cmp(oras x, oras y)
{
return(x.d<y.d);
}
int dist(oras x, oras y)
{
return (x.l+y.l+y.d-x.d);
}
int main()
{
int n,m,dmax,dc;
oras v[N];
fin>>m>>n;
for(int i=0; i<n; i++)
{
fin>>v[i].d>>v[i].l;
}
fin.close();
sort(v,v+n,cmp);
dc=dmax=dist(v[0],v[1]);
int u=0;
for(int i=2; i<n; i++)
{
if(dist(v[i-1],v[i])>dist(v[u],v[i]))
{
u=i-1;
}
dc=dist(v[u],v[i]);
if(dc>dmax)
{
dmax=dc;
}
}
fout<<dmax;
fout.close();
return 0;
}