b_t=0 # the earliest time when the bridge is empty for use
stack=[(0,1,0) for _ in range(worker)] # (time, bank, -1 * trips to/from the new house)
task=[[t3,t4],[t1,t2]] # bank= 0,1 for the old, new side. Smaller (time, bank, -trip) is selected first
while box:
t,bank,trip=heapq.heappop(stack)
box-= 1-bank # box decreases by 1 if one crosses from the old side,
t = b_t = max(t,b_t)+task[bank][0]
t+=task[bank][1] # cross from the new (old) side, need t1+t2 (t3+t4) back to the bridge.
if box==0:
return t
heapq.heappush(stack, (t,1-bank,trip-bank))