Skip to content

Instantly share code, notes, and snippets.

@jsrimr
Created June 26, 2020 11:56
Show Gist options
  • Select an option

  • Save jsrimr/3b709ad9cd7dbed35a70914a144c5f5c to your computer and use it in GitHub Desktop.

Select an option

Save jsrimr/3b709ad9cd7dbed35a70914a144c5f5c to your computer and use it in GitHub Desktop.
def solution(bridge_length, weight, truck_weights):
# 트럭 대수는 bridge_len 보다 작고, 트럭 무게 합은 weight 보다 작아야함
bridge = []
time, cur_weight, interval = 0, 0, 0
while truck_weights:
if bridge[0][1] < bridge_length and len(bridge) < bridge_length and cur_weight + truck_weights[0] <= weight: # 새로 태우자
truck = truck_weights.pop(0)
time += 1
for i, (t, c) in enumerate(bridge):
bridge[i] = [t, c + 1]
bridge.append([truck, 1])
cur_weight += truck
else: #떨구자
cursor = bridge[0][1]
time += bridge_length +1 - cursor
for i, (t, c) in enumerate(bridge):
bridge[i] = [t, c + bridge_length +1 - cursor]
cur_weight -= bridge[0][0]
bridge = bridge[1:]
if len(bridge) < bridge_length and cur_weight + truck_weights[0] <= weight: # 한 트럭 떨구면서 자연스럽게 새로운 트럭이 올라탈 수 있는 경우
truck = truck_weights.pop(0)
bridge.append([truck, 1])
cur_weight += truck
return time + bridge_length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment