python版计蒜客法师康的工人

#!/usr/bin/enc python

max_list=[]

N=int(input())

for i in range(0,N):

max_list.append([int(x) for x in input().split(” “)])

#按照开始时间从小到大排序

max_list=sorted(max_list,key=lambda x:x[0],reverse=False)

# print(max_list)

# print(max_list)

max_work_time=0

max_nowork_time=0

end_time=[]

start_time=[]

for i in max_list:

end_time.append(i[1])

start_time.append(i[1]-i[0])

max_startEnd_time=max(start_time)

print(max_startEnd_time)

# print(end_time)

# for index,item in enumerate(max_list):

thr_time=0

sign=max_list[0][0]

if N==1:

max_work_time=max_list[0][1]-max_list[0][0]

max_nowork_time=0

else:

for i in range(N-1):

#获取最长工作时间

# 获取最长无人工作时间

for_time = 0

thr_time = max_startEnd_time

if max_list[i+1][0]<=max_list[i][1]:

thr_time=max(max_list[i+1][1]- sign,max_startEnd_time)#获取最长工作时间

if max_list[i+1][0]>max(end_time[0:i+1]):

for_time= max_list[i+1][0]-max_list[i][1]

sign = max_list[i][0]

if max_work_time<thr_time:

max_work_time=thr_time

if max_nowork_time<for_time:

max_nowork_time=for_time

# print(max_work_time)

print(max_work_time,max_nowork_time)

点赞