Pagini recente » Cod sursa (job #996736) | Cod sursa (job #2819637) | Cod sursa (job #1103367) | Cod sursa (job #2594884) | Cod sursa (job #994883)
Cod sursa(job #994883)
#include<cstdio>
#include<algorithm>
using namespace std;
struct date{
int d;
int l;
};
date v[50001];
int n,m,i,j,a,b,s,smax;
FILE *f,*g;
int cmp(date x,date y){
return x.d<y.d;
}
int main(){
f=fopen("orase.in","r");
g=fopen("orase.out","w");
fscanf(f,"%d%d",&m,&n);
for(i=1;i<=n;i++){
fscanf(f,"%d%d",&v[i].d,&v[i].l);
}
sort(v+1,v+1+n,cmp);
smax=0;
j=1;
for(i=2;i<=n;i++){
s=v[i].l+v[i].d+v[j].l-v[j].d;
if(s>smax)
smax=s;
if(v[i].d+v[j].l<v[i].l+v[j].d)
j=i;
}
fprintf(g,"%d",smax);
fclose(f);
fclose(g);
return 0;
}