Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- green_time = int(input())
- free_window_duration = int(input())
- cars = deque()
- successfully_passed = 0
- while True:
- line = input()
- is_accident = False
- crossing_car, hit_index = "", None
- if line == "END":
- break
- elif line == "green":
- green_light_duration = green_time
- while green_light_duration > 0 and cars:
- crossing_car = cars.popleft()
- if green_light_duration >= len(crossing_car):
- green_light_duration -= len(crossing_car)
- successfully_passed += 1
- elif green_light_duration + free_window_duration >= len(crossing_car):
- green_light_duration = 0
- successfully_passed += 1
- break
- else:
- is_accident = True
- hit_index = -(len(crossing_car) - (green_light_duration + free_window_duration))
- break
- if is_accident:
- print("A crash happened!")
- print(f"{crossing_car} was hit at {crossing_car[hit_index]}.")
- break
- else:
- cars.append(line)
- if not is_accident:
- print(f"""Everyone is safe.
- {successfully_passed} total cars passed the crossroads.""")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement