Pagini recente » Cod sursa (job #2607287) | Cod sursa (job #927046) | Cod sursa (job #1430081) | Cod sursa (job #2654200) | Cod sursa (job #833204)
Cod sursa(job #833204)
#include<stdio.h>
#include<algorithm>
using namespace std;
struct orasele{int x,y;};
orasele v[50001];
bool compar(const orasele A, const orasele B){
if(A.x==B.x)
return A.y<B.y;
return A.x<B.x;
}
int i,n,m,vscx,sc,scmax,vscy,pp,xinc,yinc;
int main(){
freopen("orase.in","r",stdin);
freopen("orase.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++){
scanf("%d%d",&v[i].x,&v[i].y);
}
sort(v+1,v+m+1,compar);
xinc=v[1].x;
yinc=v[1].y;
sc=v[1].y;
scmax=sc;
for(i=2;i<=n;i++){
pp=1;
if(i!=n&&v[i].y>v[i].x-xinc+yinc){
sc=v[i].y;
xinc=v[i].x;
yinc=v[i].y;
pp=0;
}
else
sc+=(v[i].x-xinc);
if(sc>scmax&&pp==1)
scmax=sc+v[i].y;
else
if(sc+v[i].y>scmax&&pp==0)
scmax=sc;
}
printf("%d",scmax);
return 0;
}