This page is still under construction.

Parts of this page are still being built. What you see may change.

Bastu Bathing

Time limit3sMemory limit1024 MB

Summary
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 ax2+bx+cax^2 + bx + c).

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 0 K0 \textrm{ K} and an upper bound of 100 000 K100\,000 \textrm{ K}.

Input

The first line contains an integer 1≤N≤100 0001 \le N \le 100\,000: the number of Finns. After that follow NN lines, one per Finn. Each line contains four integers a,b,c,ta, b, c, t (−109≤a,b,c≤109,1≤t≤100 000-10^9 \le a,b,c \le 10^9, 1 \le t \le 100\,000), which represents that the Finn has happiness function ax2+bx+cax^2 + bx + c, and only tolerates temperatures between 0 K0\textrm{ K} and t Kt\textrm{ K}, inclusive. The function is guaranteed to be positive everywhere between 00 and tt.

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 10−510^{-5}.

Examples3

  1. Example 1

    Input
    2
    1 -6 10 4
    1 -6 10 7
    
    Expected output
    20.0000000000
    
  2. Example 2

    Input
    2
    -3 20 3 5
    -1 0 2 1
    
    Expected output
    36.3333333333
    
  3. Example 3

    Input
    1
    1000000 2 3 10000
    
    Expected output
    100000000020003.0000000000