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
Input Specification
The first line contains two integers
Each of the next
The traffic lights will be ordered in increasing order of
Output Specification
Output the time (in seconds) Luka needs to reach the end of the road.
Sample Input 1
2 10
3 5 5
5 2 2
Sample Output 1
12
Sample Input 2
4 30
7 13 5
14 4 4
15 3 10
25 1 1
Sample Output 2
36
In the first example, Luka will wait
Comments
Keep failing test cases 4 and 5. Any pointers?
YAY I DID IT I'M SO PROUD!!!
gj dude <3
How is it that the time limit is 0.6 seconds, yet there are solutions that run over a period of 0.6 seconds? I'm asking this since the judge keeps giving me TLE... Thank you.
Solutions show the total amount of time used. When these solutions you are talking about AC, this means that each of their cases run less than 0.6 seconds, but the total time goes over 0.6 seconds, which is fine.
Thanks.