|
<p> |
|
Matt Laundro is about to engage in his favourite activity — doing laundry! He's brought <strong>L</strong> indistinguishable loads of laundry to his local laundromat, |
|
which has <strong>N</strong> washing machines and <strong>M</strong> dryers. The <strong>i</strong>th washing machine takes |
|
<strong>W<sub>i</sub></strong> minutes to wash one load of laundry, and each dryer takes <strong>D</strong> minutes to dry a load of laundry. |
|
At any point in time, each machine may only be processing at most one load of laundry. |
|
</p> |
|
|
|
<p> |
|
As one might expect, Matt wants to wash and then dry each of his <strong>L</strong> loads of laundry. Each load of laundry will go through the following steps in order: |
|
</p> |
|
|
|
<p> |
|
<ol> |
|
<li> A non-negative amount of time after Matt arrives at the laundromat, Matt places the load in an unoccupied washing machine <strong>i</strong> </li> |
|
<li> <strong>W<sub>i</sub></strong> minutes later, he removes the load from the washing machine, placing it in a temporary holding basket (which has unlimited space) </li> |
|
<li> A non-negative amount of time later, he places the load in an unoccupied dryer </li> |
|
<li> <strong>D</strong> minutes later, he removes the load from the dryer </li> |
|
</ol> |
|
</p> |
|
|
|
<p> |
|
Matt can instantaneously add laundry to or remove laundry from a machine. |
|
Help Matt minimize the amount of time (in minutes after he arrives at the laundromat) after which he can be done drying all <strong>L</strong> loads of laundry! |
|
</p> |
|
|
|
|
|
<h3>Input</h3> |
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of times Matt goes to the laundromat. |
|
For each trip to the laundromat, there is first a line containing the space-separated integers |
|
<strong>L</strong>, <strong>N</strong>, <strong>M</strong>, and <strong>D</strong> in that order. |
|
After that is a line containing <strong>N</strong> |
|
space-separated integers, the <strong>i</strong>th of which is <strong>W<sub>i</sub></strong>. |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
<p> |
|
For the <strong>i</strong>th trip, print a line containing "Case #<strong>i</strong>: " followed by |
|
the minimum time it will take Matt to finish his laundry. |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 50 <br /> |
|
1 ≤ <strong>L</strong> ≤ 1,000,000 <br /> |
|
1 ≤ <strong>N</strong> ≤ 100,000 <br /> |
|
1 ≤ <strong>M</strong> ≤ 1,000,000,000 <br /> |
|
1 ≤ <strong>D</strong> ≤ 1,000,000,000 <br /> |
|
1 ≤ <strong>W<sub>i</sub></strong> ≤ 1,000,000,000 <br /> |
|
</p> |
|
|
|
|
|
<h3>Explanation of Sample</h3> |
|
<p> |
|
In the first case, Matt has just one load of laundry. He washes it for 1200 minutes, and dries it for 34 minutes. |
|
In the second case, Matt uses the 1-minute washer for both loads of laundry. The second load finishes at the 2-minute mark, so it finishes drying at the 12-minute mark. |
|
</p> |
|
|
|
|
|
|