#P7450. [THUSC 2017] 巧克力
[THUSC 2017] 巧克力
Problem Description
“Life is like a box of chocolates, you never know what the next one tastes like.”
Mingming received a large bar of chocolate. It contains many small pieces arranged in rows and columns. Each small piece has its own unique pattern: some are starfish, some are shells, some are conchs... and some have been crushed so that their patterns can no longer be recognized. Mingming assigns each piece a deliciousness value (). The larger this value is, the more delicious the piece is.
Just as Mingming swallowed and was about to enjoy it, Zhouzhou appeared magically. Seeing Zhouzhou’s pleading eyes, Mingming decided to pick some pieces to share with Zhouzhou.
Zhouzhou hopes that the selected chocolate pieces are connected (two pieces are connected if and only if they share a common edge), and that these pieces contain at least () different types. The crushed pieces cannot be selected.
Mingming wants to satisfy Zhouzhou, but he is also a bit “stingy” and wants to keep as much deliciousness as possible for himself. Therefore, he wants the number of selected pieces to be as small as possible. If, under the condition that the number of selected pieces is minimal, the median of the deliciousness values can be as small as possible, that would be even better. (We define the median of numbers as the -th smallest number.)
Can you help Mingming?
Input Format
Each test point contains multiple groups of testdata.
The first line contains a positive integer (), indicating the number of testdata groups.
For each group of testdata:
The first line contains three positive integers , , and .
The next lines each contain integers, describing the pattern type of each piece. If , this piece has been crushed and cannot be selected.
The next lines each contain integers, describing the deliciousness value of each piece.
Output Format
Output a total of lines. Each line contains two integers separated by a space: the minimum number of pieces and the minimum possible median deliciousness value.
If for some testdata group there is no valid selection方案, output two on the corresponding line.
1
5 4 5
3 4 3 4
5 5 -1 5
-1 4 5 5
5 5 4 2
1 -1 2 4
1 3 1 1
3 2 3 3
4 4 4 5
8 9 9 5
7 2 6 3
9 5
Hint
| Test Point ID | Constraints on | Constraints on | Partial Score Rule |
|---|---|---|---|
| 1 | or | ||
| 2 | |||
| 3~4 | |||
| 5~6 | |||
| 7~9 | or | ||
| 10 | |||
| 11~12 | |||
| 13~15 | or | ||
| 16~20 | or | ||
| 21 | This test point is not scored. |
: If the minimum number of pieces is correct, but the minimum median is wrong, the contestant can get of the score for this test point.
: If the minimum number of pieces is correct, but the minimum median is wrong, the contestant can get of the score for this test point.
Translated by ChatGPT 5