CF269D.Maximum Waterfall

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Emuskald was hired to design an artificial waterfall according to the latest trends in landscape architecture. A modern artificial waterfall consists of multiple horizontal panels affixed to a wide flat wall. The water flows down the top of the wall from panel to panel until it reaches the bottom of the wall.

The wall has height tt and has nn panels on the wall. Each panel is a horizontal segment at height hih_{i} which begins at lil_{i} and ends at rir_{i} . The ii -th panel connects the points (li,hi)(l_{i},h_{i}) and (ri,hi)(r_{i},h_{i}) of the plane. The top of the wall can be considered a panel connecting the points (109,t)(-10^{9},t) and (109,t)(10^{9},t) . Similarly, the bottom of the wall can be considered a panel connecting the points (109,0)(-10^{9},0) and (109,0)(10^{9},0) . No two panels share a common point.

Emuskald knows that for the waterfall to be aesthetically pleasing, it can flow from panel ii to panel jj () only if the following conditions hold:

  1. max(l_{i},l_{j})<min(r_{i},r_{j}) (horizontal projections of the panels overlap);
  2. h_{j}<h_{i} (panel jj is below panel ii );
  3. there is no such panel kk (h_{j}<h_{k}<h_{i}) that the first two conditions hold for the pairs (i,k)(i,k) and (k,j)(k,j) .

Then the flow for is equal to min(ri,rj)max(li,lj)min(r_{i},r_{j})-max(l_{i},l_{j}) , the length of their horizontal projection overlap.

Emuskald has decided that in his waterfall the water will flow in a single path from top to bottom. If water flows to a panel (except the bottom of the wall), the water will fall further to exactly one lower panel. The total amount of water flow in the waterfall is then defined as the minimum horizontal projection overlap between two consecutive panels in the path of the waterfall. Formally:

  1. the waterfall consists of a single path of panels ;
  2. the flow of the waterfall is the minimum flow in the path .

To make a truly great waterfall Emuskald must maximize this water flow, but there are too many panels and he is having a hard time planning his creation. Below is an example of a waterfall Emuskald wants:

Help Emuskald maintain his reputation and find the value of the maximum possible water flow.

输入格式

The first line of input contains two space-separated integers nn and tt ( 1<=n<=1051<=n<=10^{5} , 2<=t<=1092<=t<=10^{9} ), the number of the panels excluding the top and the bottom panels, and the height of the wall. Each of the nn following lines contain three space-separated integers hih_{i} , lil_{i} and rir_{i} ( 0<h_{i}<t , -10^{9}<=l_{i}<r_{i}<=10^{9} ), the height, left and right ends of the ii -th panel segment.

It is guaranteed that no two segments share a common point.

输出格式

Output a single integer — the maximum possible amount of water flow in the desired waterfall.

输入输出样例

  • 输入#1

    5 6
    4 1 6
    3 2 7
    5 9 11
    3 10 15
    1 13 16
    

    输出#1

    4
    
  • 输入#2

    6 5
    4 2 8
    3 1 2
    2 2 3
    2 6 12
    1 0 7
    1 8 11
    

    输出#2

    2
    

说明/提示

The first test case corresponds to the picture.

首页