시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB73131125.581%

문제

시장은 새로운 TV 송신 시스템을 도입하기로 했다. 도시는 길이가 D인 선분 위에 여러 개의 빌딩이 놓여져 있는 형태이다. 빌딩의 너비는 무시할 수 있을만큼 작다. 일부 빌딩의 옥상에는 TV 송신기 있으며, 그 크기도 무시할 수 있다.

TV 송신기는 TV 신호를 모든 방향으로 전송한다. 신호는 직선으로 전송되며, 빌딩을 통과할 수 없다. 도시의 일부분은 기존에 설치된 송신기로 TV 신호를 수신할 수 있다.

TV 신호를 받을 수 있는 선분을 찾고 그 길이를 출력하는 프로그램을 작성하시오.

입력

첫째 줄에 빌딩의 수 N (1 ≤ N ≤ 3·105)과 도시의 길이 D(1 ≤ D ≤ 109)가 주어진다.

다음 N개 줄에는 i번째 빌딩의 정보를 나타내는 세 개의 정수가 주어진다.

  1. 빌딩의 옥상에 송신기가 설치된 경우에 첫 번째 정수는 1이고, 설치되지 않은 경우에는 0이다.
  2. 두 번째 정수는 빌딩이 도시의 왼쪽 끝으로부터 떨어진 거리 Xi (0 ≤ Xi ≤ D) 이다.
  3. 세 번째 정수는 빌딩의 높이 Hi (1 ≤ Hi ≤ 109) 이다.

빌딩은 왼쪽으로부터 떨어진 거리가 증가하는 순으로 주어진다. 두 빌딩이 같은 곳에 있는 경우는 없다.

출력

첫째 줄에 구한 정답을 출력한다. 오차는 최대 10-3까지 허용된다.

예제 입력 1

3 10
1 2 6
0 4 3
0 8 2

예제 출력 1

6.000000

예제 입력 2

5 15
0 4 3
1 5 5
1 6 6
0 9 2
0 10 3

예제 출력 2

8.500000

문제의 그림에서 X축이 굵은선으로 되어있는 부분은 TV 신호를 받을 수 없는 곳이다.

W3sicHJvYmxlbV9pZCI6Ijk2MzAiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJUViBcdWMxYTFcdWMyZTBcdWFlMzAiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzJkY1x1YzdhNVx1Yzc0M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