Shadow Line
시간 제한10초메모리 제한2048 MB
x축 음의 방향으로 움직이는 점광원이 x = w 벽에 정확히 하나의 그림자 구간을 만드는 x 구간의 길이를 모두 더하고, 그 영역이 무한하면 -1을 출력한다.
문제
You have a point light source at the origin in the 2D plane. To the right there is an infinitely tall wall. There are some opaque vertical line segments between the light source and the wall. As a result, each line segment casts a shadow onto the wall. All of these shadows overlap to form one or more intervals on the wall.

Now imagine moving the light source along the -axis in the negative direction, effectively pulling the light further away from all the objects in a straight line. As the light source moves, the shadows move as well, potentially changing the number of shaded intervals on the wall. Your job is to compute the sum of the lengths of the intervals along the -axis for which the light source creates a single shaded interval on the wall.
입력
The first line of input contains two integers () and (), where is the number of opaque vertical segments, and is the -coordinate of the infinitely tall wall.
Each of the next lines contains three integers (), and (). Each set of three integers describes a line segment from to . All -coordinates will be unique. No two line segments will intersect or overlap.
출력
Output a single number, which is the sum of the lengths of the intervals along the -axis for which the light source creates a single shaded interval on the wall. If this sum includes an unbounded interval (i.e. there is a single shaded interval when the light source is infinitely far away), print instead. Your answer will be accepted if the absolute or relative error is within of the judge's answer.