Metro Construction
InterviewTime limit1sMemory limit1024 MB
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 engines. All engines receive the same integer voltage .
Each engine has two modes. When voltage is supplied, engine works in the first mode if , and in the second mode if .
Engine is described by its specific power in the first mode and in the second mode. In the first mode, each unit increase of voltage raises the engine's power by . In the second mode, each unit increase raises it by . So with voltage , the power of engine is in the first mode and in the second mode.
The total power of the engines must be at least to dig the tunnel. Find the minimum integer voltage that makes the total power greater than or equal to .
Input
The first line contains integers and (, ).
Each of the next lines contains three integers , , (, ).
Output
Print one integer, the minimum voltage that makes the total power at least .