Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from _collections import deque
- green_light = int(input())
- free_window = int(input())
- cars = deque()
- cars_counter = 0
- crashed = False
- command = input()
- while command != "END":
- if command == "green":
- current_car = cars.popleft() if cars else None
- left_seconds = green_light - len(current_car) if current_car else 0
- while cars and left_seconds > 0:
- current_car = cars.popleft()
- cars_counter += 1
- left_seconds -= len(current_car)
- if left_seconds == 0 and current_car:
- cars_counter += 1
- if free_window >= abs(left_seconds) and current_car:
- if left_seconds < 0:
- cars_counter += 1
- else:
- index = free_window + left_seconds
- print(f"A crash happened!\n{current_car} was hit at {current_car[index]}.")
- crashed = True
- break
- else:
- cars.append(command)
- command = input()
- if not crashed:
- print(f"Everyone is safe.\n{cars_counter} total cars passed the crossroads.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement