Pagini recente » Cod sursa (job #1465189) | Cod sursa (job #1179838) | Cod sursa (job #2912164) | Cod sursa (job #1772452) | Cod sursa (job #488328)
Cod sursa(job #488328)
#include <cstdio>
#include <algorithm>
FILE * fin = fopen ("orase.in","r");
FILE * fout = fopen ("orase.out","w");
struct street
{
int pos,length;
bool operator< (const street & a) const
{
return pos<a.pos;
}
};
street a[50000];
int main ()
{
int n,m;
fscanf(fin,"%d%d",&m,&n);
for (int i=0; i<n ;i++)
fscanf(fin,"%d%d",&a[i].pos,&a[i].length);
std::sort(a,a+n);
long long max = 0;
long long farthest = -0x3f3f3f;
for (int i=0; i<n; i++)
{
long long sum = farthest+a[i].pos+a[i].length;
if (sum>max)
max=sum;
if (a[i].length-a[i].pos>farthest)
farthest=a[i].length-a[i].pos;
}
fprintf(fout,"%d",max);
fclose(fin);
fclose(fout);
return 0;
}