#P9181. Maximum Total Area of Right Triangles
Maximum Total Area of Right Triangles
Maximum Total Area of Right Triangles
Given n right triangles where the i-th triangle has a hypotenuse of length \(r_i\). For each triangle, you can choose an altitude \(h_i\) to the hypotenuse such that \(0 \leq h_i \leq \frac{r_i}{2}\). The sum of all altitudes must satisfy \(\sum_{i=1}^{n} h_i \leq S\). The area of the i-th triangle is given by:
\(A_i = \frac{1}{2} r_i h_i\)
Your goal is to determine the maximum total area \(\sum_{i=1}^{n} A_i\) of these triangles by choosing the altitudes optimally.
Hint: To maximize the total area, assign as much altitude as possible to the triangles with a larger hypotenuse because the area contribution per unit altitude is \(\frac{r_i}{2}\). However, note that no triangle can receive more than \(\frac{r_i}{2}\) altitude.
inputFormat
The input consists of two lines:
- The first line contains two numbers \(n\) and \(S\), where \(n\) is the number of triangles and \(S\) is the maximum allowed total altitude.
- The second line contains \(n\) numbers: \(r_1, r_2, \ldots, r_n\), representing the hypotenuse lengths of the right triangles.
outputFormat
Output a single number representing the maximum possible total area of the triangles. Answers with an absolute or relative error of at most \(10^{-6}\) will be accepted.
sample
3 10
3 5 8
24.500000