丝路新程的物流中心有5个包裹需要分拣,每个包裹的处理时间分别为 [3, 1, 4, 1, 5]。为了最小化所有包裹的平均等待时间,应该采用什么策略?以下代码实现了该策略,请问 total_wait 的最终值是多少?
times = [3, 1, 4, 1, 5]
times.sort() # 贪心策略:短作业优先
total_wait = 0
current_time = 0
for t in times:
current_time += t
total_wait += current_time
print(total_wait)
14
25
31
40