Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import sys
  2.  
  3. inputl = sys.stdin.read().strip().split("\n")
  4. totaldistance = int(inputl.pop(0))
  5.  
  6. currenttime = 0
  7. current_distance = 0
  8.  
  9. light_position = 0
  10.  
  11. for light in inputl:
  12. light_position, red, green = [int(x) for x in light.split()]
  13.  
  14. currenttime += light_position - current_distance
  15. current_distance = light_position
  16.  
  17. cycle_currenttime = red + green
  18. currenttime_relative_to_cycle = cycle_currenttime - \
  19. (currenttime % cycle_currenttime)
  20. if currenttime_relative_to_cycle - green > 0:
  21. currenttime += currenttime_relative_to_cycle - green
  22. currenttime += totaldistance - light_position
  23.  
  24.  
  25. print(currenttime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement