## COCI '07 Contest 6 #2 Semafori

View as PDF

Points: 7
Time limit: 0.6s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 and , the number of traffic lights on the road and the length of the road.

Each of the next lines contains three integers , and , describing one traffic light . is the distance of the traffic light from the start of the road. and denote how long the red and green lights are on, respectively.

The traffic lights will be ordered in increasing order of . No two traffic lights will share the same position.

#### 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 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.

• commented on March 17, 2019, 7:20 p.m.

YAY I DID IT I'M SO PROUD!!!

• commented on March 18, 2019, 8:55 a.m.

gj dude <3

• commented on Dec. 9, 2018, 1:01 p.m.

Thanks.

• commented on Dec. 8, 2018, 5:53 p.m.

How is it that the time limit is 1 second, yet there are solutions that run over a period of a second? I'm asking this since the judge keeps giving me TLE... Thank you.

• commented on Dec. 9, 2018, 11:30 a.m.

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 one second, but the total time goes over one second, which is fine.