#P5299. [PKUWC2018] Slay the Spire

[PKUWC2018] Slay the Spire

Description

Jiutiao Kelian is playing a very interesting strategy game: Slay the Spire. At the beginning, her deck contains 2n2n cards. Each card has a number wiw_i written on it. There are two types of cards, with nn cards of each type:

  1. Attack cards: After playing one, it deals damage equal to the number on the card.

  2. Buff cards: After playing one, suppose the number on this buff card is xx. Then the numbers on all remaining attack cards will be multiplied by xx. It is guaranteed that the numbers on buff cards are all greater than 1.

Now Jiutiao Kelian will randomly draw mm cards from the deck with equal probability. Due to energy limits, she can play at most kk cards. Assume she always uses the strategy that can deal the maximum damage. Find the expected damage she can deal.

Suppose the answer is ans\text{ans}. You only need to output

$$\left (\text{ans}\times \frac{(2n)!}{m!(2n-m)!}\right) ~\bmod 998244353$$

Here, x!x! means i=1xi\prod_{i=1}^{x}i. In particular, 0!=10!=1.

Input Format

The first line contains a positive integer TT, denoting the number of test cases.

For each test case:

The first line contains three positive integers n,m,kn,m,k.

The second line contains nn positive integers wiw_i, representing the values on each buff card.

The third line contains nn positive integers wiw_i, representing the values on each attack card.

Output Format

Output TT lines. Each line contains a non-negative integer, representing the answer for each test case.

2
2 3 2
2 3
1 2
10 16 14
2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10
19
253973805

Hint

Sample Explanation

For example, Jiutiao Kelian draws attack cards {1,2}\{1,2\} and a buff card {3}\{3\}. The optimal strategy is to play the buff card 33 first. Then the values of the attack cards become {3,6}\{3,6\}, and then she plays 66.

Constraints

For all testdata, 1km2n30001\leq k\leq m\leq 2n\leq 3000, and 1wi1081\leq w_i\leq 10^8.

It is guaranteed that the numbers on buff cards are all greater than 1.

Let (2n)(\sum 2n) denote the sum of 2n2n over all test cases in the input.

For 10%10\% of the testdata, 12n101\leq \sum 2n\leq 10.

For 20%20\% of the testdata, 12n1001\leq \sum 2n\leq 100.

For 30%30\% of the testdata, 12n5001\leq \sum 2n\leq 500.

For another 20%20\% of the testdata, all attack cards have the same value.

For another 20%20\% of the testdata, m=km=k.

For 100%100\% of the testdata, 12n30001\leq \sum 2n\leq 3000.

Translated by ChatGPT 5