|
<p> |
|
Mr. Fox has just won the lottery! As a result, he's treated himself to some gifts — |
|
a few socks, a few rocks, a few blocks... oh, and the entire Panama canal system. |
|
</p> |
|
|
|
<p> |
|
The system has <strong>K</strong> canals, the <strong>i</strong>th of which consists of a line of |
|
<strong>N<sub>i</sub></strong> equally-sized sections. The <strong>j</strong>th section of the <strong>i</strong>th canal |
|
initially contains <strong>W<sub>i,j</sub></strong> gallons of water. There's also an initially closed lock (a retractable wall) between |
|
each pair of adjacent sections (that is, between sections 1 and 2, sections 2 and 3, and so on). |
|
As such, there are <strong>N<sub>i</sub></strong>-1 such locks in the <strong>i</strong>th canal. |
|
</p> |
|
|
|
<p> |
|
The canals are all linked to each other by an additional central hub section (also of equal size to the other sections), |
|
which initially contains <strong>H</strong> gallons of water. This section is adjacent to the 1st section of each of the canals, |
|
separated by a special initially closed lock. As such, there are <strong>K</strong> such central locks. |
|
</p> |
|
|
|
<p> |
|
Mr. Fox is relaxing in a yacht (oh, right, he also bought himself one of those) floating in the central hub section. |
|
Just for fun, he'd like to raise the water level in this section as high as possible. To do so, he may give any (potentially empty) sequence |
|
of commands to his Panama employees, one per minute. Each command consists of selecting a single lock anywhere in the canal system |
|
and toggling it from being closed to being open (or vice versa). In the following minute, the water will level out (as water tends to do) by |
|
flowing through open locks such that, for any pair of adjacent sections which are separated by an open lock, they will end up with equal |
|
amounts of water. Mr. Fox does need to obey the Panama canal system's safety regulations, however, which impose one restriction on his |
|
commands: whenever one of the <strong>K</strong> central locks adjacent to the central hub section is opened, it must be closed a |
|
minute later and then never re-opened. |
|
</p> |
|
|
|
<p> |
|
Mr. Fox loves watching water flow through his locks, especially when it allows his yacht to magically rise up. Wheeeee! By commanding his employees carefully, how much water can Mr. Fox get into the central hub section? |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 20 <br/> |
|
1 ≤ <strong>K</strong> ≤ 50 <br/> |
|
0 ≤ <strong>H</strong> ≤ 10^9 <br/> |
|
1 ≤ <strong>N<sub>i</sub></strong> ≤ 100,000 <br/> |
|
<strong>N<sub>i</sub></strong> > 1 implies |
|
<strong>N<sub>i+1</sub></strong> ≥ 2*<strong>N<sub>i</sub></strong> |
|
(for 1 ≤ <strong>i</strong> < <strong>K</strong>) <br/> |
|
0 ≤ <strong>W<sub>i,j</sub></strong> ≤ 10^9 <br/> |
|
</p> |
|
|
|
|
|
<h3>Input</h3> |
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of canal systems Mr. Fox owns. |
|
For each system, there is first a line containing the space-separated integers <strong>K</strong> and <strong>H</strong>. |
|
Then, <strong>K</strong> lines follow, the <strong>i</strong>th of which contains the integer <strong>N<sub>i</sub></strong> |
|
followed by the space-separated integers <strong>W<sub>i,1</sub></strong> ... <strong>W<sub>i,N<sub>i</sub></sub></strong>. |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
<p> |
|
For the <strong>i</strong>th canal system, print a line containing "Case #<strong>i</strong>: " followed by |
|
the maximum amount of water (in gallons) that can end up in the central hub section, rounded to 6 decimal places. |
|
</p> |
|
|
|
<p> |
|
Absolute errors of up to 5e-6 will be ignored. |
|
</p> |
|
|
|
|
|
<h3>Explanation of Sample</h3> |
|
<p> |
|
In the first case, the optimal solution is to first open and close the lock between the central hub and canal 1. |
|
This leaves the central hub with 0.5 gallons of water. Then, opening the lock between the central hub and canal 2 leaves the central hub |
|
with 1.25 gallons of water. |
|
</p> |
|
|