|
<p> |
|
It's time to settle things once and for all. Your boomerang crew has decided to challenge their rivals to a boomerang crew battle! |
|
</p> |
|
|
|
<p> |
|
Your crew has <strong>N</strong> members with strengths <strong>A<sub>1..N</sub></strong>, |
|
while the opposing crew has <strong>M</strong> members with strengths <strong>B<sub>1..M</sub></strong>. |
|
The crew battle will proceed as follows: |
|
</p> |
|
|
|
<ol> |
|
<li> Each crew will arrange its members in a line, in some order. </li> |
|
<li> A throwing contest will take place between the first person in your line, and the first person in your opponents' line. </li> |
|
<li> Whoever loses the contest (see below for details) will leave their line permanently, while the winner will stay at the front of their line. </li> |
|
<li> If one of the lines has become empty, that crew loses and the crew battle concludes. </li> |
|
<li> Otherwise, back to step 2. </li> |
|
</ol> |
|
|
|
<p> |
|
However, you're not about to play fair with your enemies — you've got the following 3 things going for you: |
|
</p> |
|
|
|
<ol> |
|
<li> You will decide the initial ordering of members for <em>both</em> crews (in step 1 of the crew battle). |
|
<li> When a member of your crew with strength <strong>S</strong> competes in a throwing contest, they'll throw their boomerang a distance of <strong>S</strong> feet. |
|
On the other hand, due to a bit of subtle poisoning you've done in advance, your enemies will get tired after each throw. |
|
In particular, when a member of the rival crew with strength <strong>S</strong> competes in a throwing contest, |
|
such that they've already competed in (and won) <strong>C</strong> throwing contests previously, |
|
they'll throw their boomerang a distance of max{<strong>S</strong> - <strong>C</strong>*<strong>D</strong>, 1} feet (where <strong>D</strong> is a set constant). |
|
<li> In each throwing contest, your crew's member will win if their throw distance is greater than <em>or equal</em> to their opponent's. |
|
</ol> |
|
|
|
<p> |
|
Despite these advantages, it's possible that you'll still be unable to emerge victorious. However, whether or not you do, you'd like to maximize the number of |
|
throwing contests that members of your crew win over the course of the crew battle (given that you choose optimal initial orderings for both lines). |
|
</p> |
|
|
|
|
|
<h3>Input</h3> |
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of battles. |
|
For each battle, there are three lines. |
|
The first line contains the space-separated integers <strong>N</strong>, <strong>M</strong>, and <strong>D</strong>. |
|
The second line contains the <strong>N</strong> space-separated integers <strong>A<sub>1</sub></strong> to <strong>A<sub>N</sub></strong>. |
|
The third line contains the <strong>M</strong> space-separated integers <strong>B<sub>1</sub></strong> to <strong>B<sub>M</sub></strong>. |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
<p> |
|
For the <strong>i</strong>th battle, print a line containing "Case #<strong>i</strong>: " followed by the maximum number of throwing contests that your crew can win. |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 75 <br /> |
|
1 ≤ <strong>N</strong>, <strong>M</strong> ≤ 100,000 <br /> |
|
1 ≤ <strong>A<sub>i</sub></strong>, <strong>B<sub>i</sub></strong>, <strong>D</strong> ≤ 1,000,000,000 <br /> |
|
</p> |
|
|
|
|
|
<h3>Explanation of Sample</h3> |
|
<p> |
|
In the first battle, your single member cannot beat theirs. In the second battle, they can (just barely). |
|
|
|
In the fourth battle, one solution is to arrange their crew as [35, 25, 5] and your crew as [10, 20, 30] to emerge victorious (in which case, 5 throwing contests will occur, of which your crew will win the last three). |
|
</p> |
|
|