Zenyk the cheater
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
The academic year is coming to an end, so Zenyk’s parents unexpectedly decided to check his gradebook!
As with any student, Zenyk’s gradebook has a certain number of grades from \(1\) to \(12\) on each page. Naturally, it is not necessary for every page to have the same number of grades, but there is at least one grade on each page.
Zenyk’s parents are only interested in the average value of his grades, so Zenyk decided to cheat and tear out some pages from his gradebook. However, since he was caught off guard, he can only tear out a few consecutive pages. Note that Zenyk is not obliged to tear out any pages if he doesn’t want to. However, if Zenyk tears out all the pages, his parents will definitely suspect something, so he will never do that!
While Zenyk is hastily trying to secretly execute his cunning plan, help him find the maximum average value of his grades he can get if he tears out the pages in an optimal way.
Input
The first line contains a positive integer \(n\) — the number of pages in Zenyk’s gradebook.
Each of the next \(n\) lines describes the grades on the corresponding page — the \(i\)-th line first gives the number \(a_i\) — the number of grades on page \(i\), and then, separated by a space, the grades themselves \(b_{i,1}\), \(b_{i,2}\), ..., \(b_{i,a_i}\).
Output
Print a single number — the answer to the problem.
Your answer will be considered correct if the absolute or relative error from the correct answer is no more than \(10^{-7}\).
Constraints
\(1 \le n \le 10^6\),
\(1 \le a_i \le 10^6\),
\(1 \le \sum_{i=1}^{n} a_i \le 10^6\),
\(1 \le b_{i,j} \le 12\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 2 2 12 11 1 1 | 11.5 |
| Input (stdin) | Output (stdout) |
|---|---|
| 3 1 2 2 12 12 1 9 | 11 |
Notes
In the first test, Zenyk should tear out the second page, so the parents will only see two grades from the first page — \(11\) and \(12\), and will think their son is an excellent student!
In the second test, Zenyk would like to tear out the first and third pages, but he doesn’t have time for that, so he can only tear out the first page and get an average grade of \(11\).
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|