Pagini recente » Cod sursa (job #1922866) | Cod sursa (job #1430757) | Cod sursa (job #451626) | Cod sursa (job #548034) | Cod sursa (job #245188)
Cod sursa(job #245188)
#include<stdio.h>
#include<stdlib.h>
#define NM 50000
struct str{int d,l,dif;};
typedef str *pstr;
int fcmp(void const*a,void const*b){
((pstr)a)->d-((pstr)b)->d;
}
int main(){
freopen("orase.in","r",stdin);
freopen("orase.out","w",stdout);
int m,n,i,j,lc,lmax=0,dmax;
str v[NM+1];
scanf("%d%d",&m,&n);
for(i=0;i<n;++i) {
scanf("%d%d",&v[i].d,&v[i].l);
v[i].dif=v[i].l-v[i].d;
}
qsort(v,n,sizeof(v[0]),fcmp);
dmax=v[0].dif;
for(i=1;i<n;++i){
lc=v[i].l+v[i].d+dmax;
if(lmax<lc) lmax=lc;
if(dmax<v[i].dif) dmax=v[i].dif;
}
printf("%d",lmax);
return 0;
}