【问题描述】
三个工人从8点开始上班。第一个工人在300秒(从8点开始)开始干活,一直到1000秒。第二个工人在800秒开始,在 1300秒结束。第三个工人在1500秒开始,在2100秒结束。期间最长的至少有一个工人在干活的连续时间LWT为1000秒(从300秒到1300秒),而最长的无人干活的连续时间LRT(从第一个工人开始一直到最后一个工人结束)为200秒(从1300秒到1500秒)。
你的任务是编一个程序,读入一个有N个工人(1 <= N <= 5000)干活的工作时间列表,计算以下两点(均以秒为单位):
最长至少有一人在工作的时间段LWT。
最长的无人工作的时间段LRT。(从有人工作开始算起)
【输入形式】
第1行:一个整数N。
第2至第N+1行:每行两个小于1000000的非负整数,表示一个工人的开始时刻与结束时刻。
【输出形式】
一行,两个整数,即题目所要求的两个答案LWT与LRT。
【样例输入】
3
300 1000
800 1300
1500 2100
【样例输出】
1000 200
a=int(input())
b=[]
for i in range(a): # 将输入转化为矩阵,每个元素为整形
b.append(list(map(int, input().split())))
temp=9999
temp1=0
for i in range(a):
if b[i][0]<temp:
temp=b[i][0]
temp1=i
temp2=0
temp3=0
for i in range(a):
if b[i][1]>temp2:
temp2=b[i][1]
temp3=i
c=[int(0) for i in range(temp,temp2+1)]
#print(len(c))
#print(c)
for i in range(a):
for j in range(b[i][0]-temp,b[i][1]-temp):
c[j]=c[j]+1
#IndexError: list index out of range 1.越界 2.列表为空
count=0
max=0
max1=0
count1=0
#print(c)
#print(int(temp2+1-temp))
for i in range(0,temp2+1-temp):
if i !=0 and c[i-1]!=0 and c[i]==0:
count = 0
if i != 0 and c[i - 1] == 0 and c[i] != 0:
count1 = 0
if c[i]!=0 and i!=temp2-temp:
count+=1
if count>max:
max=count
continue
if c[i] == 0 and i!=temp2-temp:
i+=1
count1+=1
if count1>max1:
max1=count1
continue
print(max,max1)