#P9181. [COCI 2022/2023 #5] Zastave

[COCI 2022/2023 #5] Zastave

Problem Description

There are nn right triangles. The ii-th right triangle has hypotenuse length rir_i. The sum of the heights of these right triangles does not exceed SS. Find the maximum possible total area of these nn right triangles.

Input Format

The first line contains two integers n,S (1n105,1S1010)n, S\ (1\le n\le 10^5,1\le S\le 10^{10}), representing the number of triangles and the maximum allowed sum of their heights.

The second line contains nn integers ri (1ri105)r_i\ (1\le r_i\le 10^5).

Output Format

Output the maximum possible total area of these nn right triangles (keep 1010 digits after the decimal point). Your output is considered correct if its absolute error or relative error is at most 10610^{-6} compared to the answer.

2 3
4 5

6.5200982141

1 6
10

24.0000000000

4 7
5 5 6 6

18.5706715170

Hint

Explanation for sample 22:

The maximum possible case is a triangle with side lengths 6,8,106, 8, 10, with area 2424.

Subtask ID Additional Constraints Score
00 Sample only 00
11 n100n\le 100 3737
22 n1000n\le 1000 2020
33 No additional constraints 4343

Translated by ChatGPT 5