아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Stop & Go

면접 대비

시간 제한2초메모리 제한1024 MB

요약
자동차가 속도 1로 주행하며 각 신호등에서 멈출 수 있을 때, 도로 끝에 도착하는 시각을 구합니다.
난이도

보통10점 중 4점

유형
수학, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Mr. Drive, a.k.a. Mr. D, is famous for his thorough safe driving. Not only he always drives a car at an exact legal speed, but also he immediately stops a car if a traffic light turns red from green when he just enters a crossing, and he immediately starts a car at an exact legal speed when a traffic light just turns green from red.

Mr. D's next driving course is a simple straight road with length LL and the legal speed limit 11 per second. Mr.D will start his drive at time 00. The road has NN traffic lights numbered 11 through NN. The traffic light ii is at a distance of x_ix\_i from the start point. At time 00, all the NN traffic lights are green. The ii-th traffic light turns red from green after g_ig\_i seconds, then turns green from red after r_ir\_i, and then turns red from green after g_ig\_i seconds, then turns green from red after r_ir\_i, and so on.

In this situation, Mr. D will start from the start point and run a car at speed 11 per second. If the ii-th traffic light is green or just turns green from red (but not just turns red from green) when Mr. D reaches x_ix\_i, Mr. D won't stop and go through the crossing at speed 11 per second. If the ii-th traffic light is red or just turns red from green (but not just turns green from red) when Mr. D reaches x_ix\_i, Mr. D will stop until the ii-th traffic light turns green.

Your task is to compute the time in seconds when Mr. D reaches point LL, for given NN traffic lights.

입력

The first line of the input consists of two integers, the number NN (1≤N≤100,0001 ≤ N ≤ 100\\,000) of traffic lights on the road and the length LL (1≤L≤1091 ≤ L ≤ 10^9) of the road. The ii-th of the following NN lines has three integers x_ix\_i, g_ig\_i, and r_ir\_i, where x_ix\_i (1≤x_i<L1 ≤ x\_i < L) is the position of the ii-th traffic light from the start point, g_ig\_i (1≤g_i≤1091 ≤ g\_i ≤ 10^9) is the duration the ii-th traffic light is green, and r_ir\_i (1≤r_i≤1091 ≤ r\_i ≤ 10^9) is the duration the ii-th traffic light is red. You can assume all the positions of the traffic lights are different. In other words, x_i≠x_jx\_i \ne x\_j holds for all i≠ji \ne j.

출력

Output in a line a single integer, which is the time in seconds when Mr. D reaches point LL.

예제3

  1. 예제 1

    입력
    3 10
    3 2 2
    6 1 1
    9 2 5
    
    예상 출력
    15
    
  2. 예제 2

    입력
    1 100
    50 1000 1
    
    예상 출력
    100
    
  3. 예제 3

    입력
    3 100
    70 10 50
    20 10 15
    50 50 10
    
    예상 출력
    150