Bastu Bathing
Time limit3sMemory limit1024 MB
Each of N Finns contributes a quadratic happiness on [0, t_i] and zero above t_i; find the temperature maximizing the total sum.
- Level
Medium7 of 10
- Topics
- Geometry, Math, Sorting, Implementation
- Solved
- No attempts yet
Problem
Finns love bathing in a bastu. That is not so strange, really. Bastu bathing feels good, and it usually happens in pleasant company.
In company, problems often arise. The most important thing when bathing in a bastu is to set the temperature right. A Finn is very particular about the temperature of the bastu. Different Finns have different maximum temperatures they tolerate. If the temperature is too high for a certain Finn, that Finn goes home. Within the temperature interval a certain Finn can handle, the Finn is also more or less happy depending on the temperature. A Finn's happiness is given by a quadratic function (of the form ).
A large company of Finns is now going to bathe in a bastu and needs your help. Can you determine the maximum sum of the Finns' happiness if the bastu temperature is set optimally? If the temperature is set higher than a Finn tolerates, that Finn does not contribute to the total happiness at all (they have gone home). The temperature is given in kelvin, with a lower bound of and an upper bound of .
Input
The first line contains an integer : the number of Finns. After that follow lines, one per Finn. Each line contains four integers (), which represents that the Finn has happiness function , and only tolerates temperatures between and , inclusive. The function is guaranteed to be positive everywhere between and .
Output
Print a single number: the greatest possible happiness that can be achieved if the temperature is set right. The answer will be accepted if it has a relative or absolute error of at most .