#P7190. [COCI 2007/2008 #6] SEMAFORI

[COCI 2007/2008 #6] SEMAFORI

Problem Description

Luka is driving a truck, and there are nn traffic lights on the road.

For each traffic light, he knows how long the red light and the green light stay on (repeating in a cycle).

When Luka starts driving, all traffic lights are red and their cycles start at the same time.

Luka moves 11 unit of distance per second. When a traffic light is red, he must stop and wait until it turns green.

Write a program to determine how much time Luka needs to reach the end of the road.

The start of the road is at 00, and the end is at ll.

Input Format

The first line contains two integers n,ln, l, which represent the number of traffic lights and the length of the road.

Each of the next nn lines contains three integers d,r,gd, r, g. dd is the distance from the traffic light to the start of the road, and rr and gg are the durations of the red and green lights.

The traffic lights are given in increasing order of dd.

No two traffic lights are at the same position.

Output Format

The first line contains one positive integer, which is the time Luka needs to reach the end of the road.

2 10
3 5 5
5 2 2 

12
4 30
7 13 5
14 4 4
15 3 10
25 1 1 

36

Hint

Sample #1 Explanation

In the first sample, Luka waits 22 seconds at the first traffic light. Then he reaches the second traffic light, which is green, so he can pass immediately.

Constraints

For 100%100\% of the testdata, 1n1001 \le n \le 100, 1l1031 \le l \le 10^3, 1d<l1 \le d < l, 1r1001 \le r \le 100, 1g1001 \le g \le 100.

Notes

  • This problem is worth 3030 points in total.
  • This problem enables the O2 optimization switch by default.
  • The problem is translated from COCI2007-2008 CONTEST #6 T2 SEMAFORI, translated by
    https://www.luogu.com.cn/user/219791

Translated by ChatGPT 5