#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int start,end;
}a[5010];
bool cmp(node c,node d){
return c.start<d.start;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].start>>a[i].end;
}
sort(a+1,a+1+n,cmp);
int st=a[1].start,ed=a[1].end;
int max1=ed-st; //最长的有人挤奶时间
int max2=0; //最长无人挤奶时间
for(int i=2;i<=n;i++)
{
if(a[i].start<ed){ //存在交集,前后连上
ed=max(ed,a[i].end);
max1=max(max1,ed-st);
}
else{ //前后连不上
max2=max(max2,a[i].start-ed);
st=a[i].start; //更新一下当前的st和ed
ed=a[i].end;
}
}
cout<<max1<<" "<<max2<<endl;
return 0;
}
//看是否存在交集
//前提是start必须排序
//有交集就是更新最长有人挤奶时间
//无交集就是更新最长无人挤奶时间
02-15
1万+
10-02
100
09-28
1110
10-02
144