题目收集
题目列表题单
返回列表

Dune

CodeforcesP0042· 1000ms· 256 MB· ZJU Summer 2026 Contest 4原题链接
模拟数据结构优化

创建于 2026/07/17 · 更新于 2026/07/17

题目描述

Colin is a big fan of the Dune series movies and was deeply impressed by the scene in which Paul Atreides summons and rides a giant sandworm!

Colin noticed that the timing of summoning sandworms is very important. There are always so many mysteries hidden under the calm dunes! Therefore, he modeled "Summoning Sandworms" and designed a problem for you:

To simplify the problem, we describe the topography of the dunes with a one-dimensional numerical axis. There are nnn sandworms moving parallel to the number axis. Specifically, at the initial time t=0t=0t=0, the body of the iii-th sandworm can be described by the segment [li,ri][l_i,r_i][li​,ri​] (thus, the length of the iii-th sandworm is ri−lir_i-l_iri​−li​), and it will move in the positive direction of the number axis at a speed of viv_ivi​ per second. That is, at time ttt, the body of the iii-th worm can be described by the segment [li+vi×t,ri+vi×t][l_i+v_i\times t,r_i+v_i\times t][li​+vi​×t,ri​+vi​×t].

Your position is at coordinate xxx, and you can choose any nonnegative real number time t′t't′ to summon sandworms passing through your position (i.e., at time t′t't′, the coordinate x∈[li+vi×t′,ri+vi×t′]x\in [l_i+v_i\times t',r_i+v_i\times t']x∈[li​+vi​×t′,ri​+vi​×t′] ). However, there may be more than one sandworm passing through your position at this moment. In this case, you can only summon the shortest one among these sandworms.

There's nothing more exciting than summoning a giant sandworm! So Colin wants to know what is the longest length of sandworm you can possibly summon.

输入格式

The first line contains two integers n,x (1≤n≤105,0≤x≤109)n, x\ (1\le n\le 10^5, 0\le x\le 10^9)n,x (1≤n≤105,0≤x≤109), representing the number of sandworms and your position.

In the following nnn lines, each line contains three integers li,ri,vi (−109≤li≤ri≤109,1≤vi≤109)l_i,r_i,v_i\ (-10^9\le l_i\le r_i\le 10^9, 1\le v_i\le 10^9)li​,ri​,vi​ (−109≤li​≤ri​≤109,1≤vi​≤109), describing the iii-th sandworm.

It's guaranteed that at least one sandworm will pass by your position.

输出格式

Output a single integer representing the longest length of sandworm you can possibly summon.

样例输入 #1

4 3
4 1000000000 1
2 4 1
1 1000000000 1000000000
1 2 3

样例输出 #1

2