这个也很简单。
1 /*
2 ID:31440461
3 PROG:milk2
4 LANG:C++
5 */
6 #include<iostream>
7 #include<fstream>
8 using namespace std;
9 const int maxtable=1000000+100;
10
11 int main()
12 {
13 int b[maxtable],e[maxtable];
14 int n,sum=0,freetime=0,milktime=0,mark=0;
15 ifstream fin("milk2.in");
16 ofstream fout("milk2.out");
17 memset(b,0,sizeof(b));
18 memset(e,0,sizeof(e));
19 fin>>n;
20 for (int i=1;i<=n;i++)
21 {
22 int be,en;
23 fin>>be>>en;
24 b[be]++;
25 e[en]++;
26 }
27
28 bool free=1;
29 for (int i=0;i<maxtable;i++)
30 {
31 if (b[i]) sum+=b[i];
32 if (e[i]) sum-=e[i];
33 if (sum && free)
34 {
35 if(i-mark>freetime && mark) freetime=i-mark;
36 mark=i;
37 free=0;
38
39 }
40 if (!sum && !free)
41 {
42 if(i-mark>milktime) milktime=i-mark;
43 mark=i;
44 free=1;
45 }
46 }
47 fout<<milktime<<' '<<freetime<<endl;
48 return 0;
49 }
50