#P10098. [ROIR 2023] 地铁建设 (Day 2)

    ID: 10773 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学二分2023Special Judge枚举ROIR(俄罗斯)

[ROIR 2023] 地铁建设 (Day 2)

Background

Translated from ROIR 2023 D2T1.

A shield tunneling machine used to build subway tunnels has nn motors. All motors are connected in parallel, so the voltage across all motors is the same.

Each motor has two modes. Suppose the voltage received by all motors is xx. Then, for the ii-th motor, if xzix \le z_i, it works in the first mode; otherwise, it works in the second mode.

The unit current of the ii-th motor is aia_i in the first mode and bib_i in the second mode. Therefore, by P=UIP = UI, when the motor is in the first mode, each increase of 11 unit of voltage increases its power by aia_i units; when it is in the second mode, each increase of 11 unit of voltage increases its power by bib_i units. In other words, when the voltage is xx, if the ii-th motor is in the first mode, it runs at power ai×xa_i \times x; if it is in the second mode, it runs at power ai×zi+bi×(xzi)a_i \times z_i + b_i \times (x - z_i).

Problem Description

What is the minimum voltage that must be provided (the voltage must be an integer) so that the total power of all motors is greater than or equal to pp?

Input Format

The first line contains two integers nn and pp.

The next nn lines each contain three integers zi,ai,biz_i, a_i, b_i.

Output Format

Output one integer, the minimum voltage.

1 6
4 1 2
5
3 15
2 3 3
4 2 1
5 2 2
3

Hint

This problem uses bundled testdata.

Subtask ID Points Special Property
11 2020 n=1n = 1
22 ai,bi100,p105a_i, b_i \le 100, p \le 10^5
33 All ziz_i are equal
44 n2n \le 2
55

For 100%100\% of the data, 1n1001 \le n \le 100, 1p10121 \le p \le 10^{12}, 1zi1091 \le z_i \le 10^9, 1ai,bi1041 \le a_i, b_i \le 10^4.

Translated by ChatGPT 5