Skip to content

Commit 6c7d876

Browse files
committed
[BOJ] #13335. 트럭 / 실버1 / 60분 / 힌트사용
1 parent 2086de5 commit 6c7d876

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sys
2+
from collections import deque
3+
4+
input = sys.stdin.readline
5+
6+
# 1. 입력 처리
7+
n, w, L = map(int, input().split())
8+
trucks = list(map(int, input().split()))
9+
10+
# 2. 초기화
11+
bridge = deque() # 다리 위 트럭들: (트럭 무게, 다리에서 빠져나갈 시간)
12+
current_weight = 0 # 다리 위의 현재 총 무게
13+
time = 0 # 현재 시간
14+
truck_index = 0 # 대기 중인 트럭의 인덱스
15+
16+
# 3. 시뮬레이션 수행
17+
while truck_index < n or bridge:
18+
time += 1 # 시간 + 1
19+
20+
# 3.1 다리에서 빠져나갈 트럭 제거
21+
if bridge and bridge[0][1] == time: # 다리에서 나갈 시간인지 확인
22+
truck_weight, _ = bridge.popleft()
23+
current_weight -= truck_weight
24+
25+
# 3.2 새로운 트럭을 다리에 올릴 수 있는지 확인
26+
if truck_index < n and current_weight + trucks[truck_index] <= L:
27+
bridge.append((trucks[truck_index], time + w)) # 트럭 추가 (무게, 나갈 시간)
28+
current_weight += trucks[truck_index]
29+
truck_index += 1
30+
31+
# 4. 결과 출력
32+
print(time)

0 commit comments

Comments
 (0)