def findCrossingTime(self, n: int, k: int, time: List[List[int]]) -> int:
ans = 0
# (leftToRight + rightToLeft, i)
leftBridgeQueue = [(-leftToRight - rightToLeft, -i)
for i, (leftToRight, pickOld, rightToLeft, pickNew) in enumerate(time)]
rightBridgeQueue = 
# (time to be idle, i)
leftWorkers = 
rightWorkers = 
while n > 0 or rightBridgeQueue or rightWorkers:
# Idle left workers get on the left bridge.
while leftWorkers and leftWorkers <= ans:
i = heapq.heappop(leftWorkers)
heapq.heappush(leftBridgeQueue, (-time[i] - time[i], -i))
# Idle right workers get on the right bridge.
while rightWorkers and rightWorkers <= ans:
i = heapq.heappop(rightWorkers)
heapq.heappush(rightBridgeQueue, (-time[i] - time[i], -i))
# If the bridge is free, the worker waiting on the right side of the
# bridge gets to cross the bridge. If more than one worker is waiting
# on the right side, the one with the lowest efficiency crosses first.
i = -heapq.heappop(rightBridgeQueue)
ans += time[i]
heapq.heappush(leftWorkers, (ans + time[i], i))
elif leftBridgeQueue and n > 0:
# If the bridge is free and no worker is waiting on the right side, and
# at least one box remains at the old warehouse, the worker on the left
# side of the river gets to cross the bridge. If more than one worker
# is waiting on the left side, the one with the lowest efficiency
# crosses first.
i = -heapq.heappop(leftBridgeQueue)
ans += time[i]
heapq.heappush(rightWorkers, (ans + time[i], i))
n -= 1
# Advance the time of the last crossing worker.
ans = min(leftWorkers if leftWorkers and n > 0 else math.inf,
rightWorkers if rightWorkers else math.inf)