Skip to content

Commit 7a2ce85

Browse files
committed
[PGS] 다리를 지나는 트럭 / Level2 / 20분
1 parent 31e887e commit 7a2ce85

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def solution(bridge_length, weight, truck_weights):
2+
bridge = []
3+
all_weight = 0
4+
t = 0
5+
while truck_weights or bridge:
6+
t += 1
7+
8+
if bridge and t - bridge[0][1] == bridge_length:
9+
truck, _ = bridge.pop(0)
10+
all_weight -= truck
11+
12+
if truck_weights and all_weight + truck_weights[0] <= weight:
13+
truck = truck_weights.pop(0)
14+
bridge.append([truck, t])
15+
all_weight += truck
16+
17+
return t

0 commit comments

Comments
 (0)