Semafori
Luka is driving his truck along a long straight road with many traffic lights. For each traffic light he knows how long the red and green lights will be on (the cycle repeating endlessly).
When Luka starts his journey, all traffic lights are red and just started their cycle. Luka moves one distance unit per second. When a traffic light is red, he stops and waits until it turns green.
Write a program that determines how much time Luka needs to reach the end of the road. The start of the road is at distance zero, the end at distance L.
The traffic lights will be ordered in increasing order of D. No two traffic lights will share the same position.
Input:
2 10
3 5 5
5 2 2
Output:
12Input:
4 30
7 13 5
14 4 4
15 3 10
25 1 1
Output:
36In the first example, Luka will wait 2 seconds at the first traffic light. After that he will reach the second traffic light while it is green and be able to pass through immediately.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.