|
<p> |
|
Matt Laundro is about to engage in his favourite activity — doing laundry! He's brought <strong>L</strong> loads of laundry to his local laundromat, |
|
which has recently been cracking down on excessive washer and dryer usage. It turns out the other customers weren't very thrilled when they saw Matt using |
|
a billion washers and dryers simultaneously, so he's now been restricted to just one washer and one dryer. |
|
Matt's <strong>i</strong>th load of laundry takes <strong>W<sub>i</sub></strong> minutes to wash, and <strong>D<sub>i</sub></strong> minutes to dry. |
|
As is usually the case with laundry, each load takes at least as long to dry as it does to wash. |
|
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. Unfortunately, the laundromat closes in <strong>K</strong> minutes, |
|
so he might not be able to get through every load. But he'll try his best! If he chooses to wash and dry the <strong>i</strong>th load of laundry, it 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 the washing machine </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 the dryer </li> |
|
<li> <strong>D<sub>i</sub></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. He can choose to wash and dry any of his loads and they can be washed and dried in any order |
|
as long as they each follow the steps above. |
|
Help Matt maximize the number of loads he can finish washing and drying in <strong>K</strong> minutes, and amongst all the ways he could finish that many loads, |
|
find the minimum amount of time it will take for all of those loads to be washed and dried. |
|
</p> |
|
|
|
|
|
|
|
|
|
<h3>Input</h3> |
|
<p> |
|
In this problem, the sequences <strong>W</strong> and <strong>D</strong> are generated using a pseudo-random number generator. |
|
The generator first produces two length-<strong>L</strong> sequences <strong>X</strong> and <strong>Y</strong>. |
|
<strong>X<sub>1</sub></strong> and <strong>Y<sub>1</sub></strong> are given, and the remaining terms |
|
<strong>X<sub>2</sub></strong>...<strong>X<sub>L</sub></strong> and <strong>Y<sub>2</sub></strong>...<strong>Y<sub>L</sub></strong> are computed as follows: |
|
</p> |
|
|
|
<p> |
|
<strong>X<sub>i</sub></strong> = ( (<strong>A<sub>x</sub></strong> * <strong>X<sub>i-1</sub></strong> + <strong>B<sub>x</sub></strong>) mod <strong>C<sub>x</sub></strong>) + 1 |
|
<br /> |
|
<strong>Y<sub>i</sub></strong> = ( (<strong>A<sub>y</sub></strong> * <strong>Y<sub>i-1</sub></strong> + <strong>B<sub>y</sub></strong>) mod <strong>C<sub>y</sub></strong>) + 1 |
|
</p> |
|
|
|
<p> |
|
After <strong>X</strong> and <strong>Y</strong> are generated, <strong>W</strong> and <strong>D</strong> are computed as follows: |
|
</p> |
|
|
|
<p> |
|
<strong>W<sub>i</sub></strong> = min {<strong>X<sub>i</sub></strong>, <strong>Y<sub>i</sub></strong>} |
|
<br /> |
|
<strong>D<sub>i</sub></strong> = max {<strong>X<sub>i</sub></strong>, <strong>Y<sub>i</sub></strong>} |
|
</p> |
|
|
|
<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> and <strong>K</strong>, |
|
then a line containing the space-separated integers <strong>A<sub>x</sub></strong>, <strong>B<sub>x</sub></strong>, <strong>C<sub>x</sub></strong>, and <strong>X<sub>1</sub></strong>, |
|
then a line containing the space-separated integers <strong>A<sub>y</sub></strong>, <strong>B<sub>y</sub></strong>, <strong>C<sub>y</sub></strong>, and <strong>Y<sub>1</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 maximum number of loads |
|
Matt can finish before the laundromat closes, and the minimum amount of time it will take to finish that many. |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 50 <br /> |
|
1 ≤ <strong>L</strong> ≤ 500,000 <br /> |
|
1 ≤ <strong>K</strong> ≤ 1,000,000,000 <br /> |
|
1 ≤ <strong>A<sub>x</sub></strong>, <strong>B<sub>x</sub></strong>, <strong>C<sub>x</sub></strong> ≤ 1,000,000,000 <br /> |
|
1 ≤ <strong>A<sub>y</sub></strong>, <strong>B<sub>y</sub></strong>, <strong>C<sub>y</sub></strong> ≤ 1,000,000,000 <br /> |
|
1 ≤ <strong>X<sub>1</sub></strong> ≤ <strong>C<sub>x</sub></strong> <br /> |
|
1 ≤ <strong>Y<sub>1</sub></strong> ≤ <strong>C<sub>y</sub></strong> <br /> |
|
</p> |
|
|
|
|
|
<h3>Explanation of Sample</h3> |
|
<p> |
|
In the first case, <strong>W</strong> and <strong>D</strong> are the same: {1, 3, 5, 7}. Matt can finish the first three loads in 14 minutes. He starts by washing the third load, which takes 5 minutes. |
|
Then, while that load is drying he can wash the first and second loads. |
|
|
|
The second case is the same, except Matt now has just enough time to wash all of the loads. He can start by washing the fourth load, which takes 7 minutes. |
|
|
|
In the third case, <strong>W</strong> = {2, 1, 6, 2, 1, 3} and <strong>D</strong> = {3, 4, 7, 5, 10, 6}. |
|
</p> |
|
|
|
|
|
|