/* ID: m1590291 TASK: milk2 LANG: C++ */ #include <iostream> #include <algorithm> #include <fstream> #define MAX 5005 using namespace std; struct Node { int begin; int end; }a[MAX]; bool cmp(Node x,Node y) { return x.begin<y.begin; //按开始时间 a 进行排序 } int main() { ifstream fin("milk2.in"); ofstream fout("milk2.out"); int T; int f[MAX]; while(fin>>T) { if(T<1 || T>5000) break; for(int i=0;i<T;i++) fin>>a[i].begin>>a[i].end; sort(a,a+T,cmp); int start=a[0].begin,ans1=a[0].end-a[0].begin,ans2=0; f[0]=a[0].end; for(int i=1;i<T;i++) { if(a[i].begin <= f[i-1]) f[i]=max(f[i-1],a[i].end); else{ start=a[i].begin; f[i]=a[i].end; ans2=max(ans2,a[i].begin-f[i-1]); } ans1=max(ans1,f[i]-start); } fout<<ans1<<" "<<ans2<<endl; } return 0; }