#903
Silver V
SEMAFORI
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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 first line contains two integers N and L (1 ≤ N ≤ 100, 1 ≤ L ≤ 1000), the number of traffic lights on the road and the length of the road. Each of the next N lines contains three integers D, R and G, describing one traffic light (1 ≤ D < L, 1 ≤ R ≤ 100, 1 ≤ G ≤ 100). D is the distance of the traffic light from the start of the road. R and G denote how long the red and green lights are on, respectively. The traffic lights will be ordered in increasing order of D. No two traffic lights will share the same position.

출력

Output the time (in seconds) Luka needs to reach the end of the road.

예제 입력 1

2 10
3 5 5
5 2 2

예제 출력 1

12

예제 입력 2

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

예제 출력 2

36
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Silver V1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.