Under construction

Still being built. Things may change

Metro Construction

Interview

Time limit1sMemory limit1024 MB

Summary
Find the smallest integer voltage x so that the total power of n two-mode engines reaches at least p.
Level

Medium4 of 10

Topics
Binary search, Math
Solved
No attempts yet

Statement

The drilling rig Megabur 2022, used to dig subway tunnels in Bytesburg, has nn engines. All engines receive the same integer voltage xx.

Each engine has two modes. When voltage xx is supplied, engine ii works in the first mode if x≤zix \le z_i, and in the second mode if x>zix > z_i.

Engine ii is described by its specific power aia_i in the first mode and bib_i in the second mode. In the first mode, each unit increase of voltage raises the engine's power by aia_i. In the second mode, each unit increase raises it by bib_i. So with voltage xx, the power of engine ii is aixa_i x in the first mode and aizi+bi(x−zi)a_i z_i + b_i(x - z_i) in the second mode.

The total power of the engines must be at least pp to dig the tunnel. Find the minimum integer voltage that makes the total power greater than or equal to pp.

Input

The first line contains integers nn and pp (1≤n≤1001 \le n \le 100, 1≤p≤10121 \le p \le 10^{12}).

Each of the next nn lines contains three integers ziz_i, aia_i, bib_i (1≤zi≤1091 \le z_i \le 10^9, 1≤ai,bi≤1041 \le a_i, b_i \le 10^4).

Output

Print one integer, the minimum voltage that makes the total power at least pp.

Examples2

  1. Example 1

    Input
    1 6
    4 1 2
    
    Expected output
    5
    
  2. Example 2

    Input
    3 15
    2 3 3
    4 2 1
    5 2 2
    
    Expected output
    3