File size: 2,943 Bytes
07f695f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
It's time to settle things once and for all. Your boomerang crew has decided
to challenge their rivals to a boomerang crew battle!
Your crew has **N** members with strengths **A1..N**, while the opposing crew
has **M** members with strengths **B1..M**. The crew battle will proceed as
follows:
1. Each crew will arrange its members in a line, in some order.
2. A throwing contest will take place between the first person in your line, and the first person in your opponents' line.
3. Whoever loses the contest (see below for details) will leave their line permanently, while the winner will stay at the front of their line.
4. If one of the lines has become empty, that crew loses and the crew battle concludes.
5. Otherwise, back to step 2.
However, you're not about to play fair with your enemies — you've got the
following 3 things going for you:
1. You will decide the initial ordering of members for _both_ crews (in step 1 of the crew battle).
2. When a member of your crew with strength **S** competes in a throwing contest, they'll throw their boomerang a distance of **S** 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 **S** competes in a throwing contest, such that they've already competed in (and won) **C** throwing contests previously, they'll throw their boomerang a distance of max{**S** \- **C*****D**, 1} feet (where **D** is a set constant).
3. In each throwing contest, your crew's member will win if their throw distance is greater than _or equal_ to their opponent's.
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).
### Input
Input begins with an integer **T**, the number of battles. For each battle,
there are three lines. The first line contains the space-separated integers
**N**, **M**, and **D**. The second line contains the **N** space-separated
integers **A1** to **AN**. The third line contains the **M** space-separated
integers **B1** to **BM**.
### Output
For the **i**th battle, print a line containing "Case #**i**: " followed by
the maximum number of throwing contests that your crew can win.
### Constraints
1 ≤ **T** ≤ 75
1 ≤ **N**, **M** ≤ 100,000
1 ≤ **Ai**, **Bi**, **D** ≤ 1,000,000,000
### Explanation of Sample
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).
|