Pagini recente » Cod sursa (job #1042761) | Cod sursa (job #2802281) | Cod sursa (job #330194) | Cod sursa (job #416123) | Cod sursa (job #1206177)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream fi("orase.in");
ofstream fo("orase.out");
const int maxn = 50004;
struct oras{
int x;
int y;
};
oras v[maxn];
int d,maxd=0;
int i,n,m;
bool comp(oras a,oras b){
return (a.x<b.x);
}
int main(){
fi>>m>>n;
for(i=1;i<=n;i++) fi>>v[i].x>>v[i].y;
sort(v+1,v+n+1,comp);
d=v[1].y-v[1].x;
for(i=2;i<=n;i++){
if(d+v[i].x+v[i].y>maxd) maxd=d+v[i].x+v[i].y;
if(v[i].y-v[i].x>d) d=v[i].y-v[i].x;
}
fo<<maxd;
fi.close();
fo.close();
return 0;
}