#P8486. Expected Prize Enthusiasm
Expected Prize Enthusiasm
Expected Prize Enthusiasm
In an OI-style contest, each of the n contestants reaches the score‐line with probability \(p_i\). After the simulation contest, the awards ceremony starts. Two committees set the prizes:
- uuku has set \(A\) types of prizes. For each prize type he set, if it is awarded (i.e. given to at least one winner) then the number of winners receiving that prize must be even (in pairs). (Awarding 0 winners is allowed and is considered not used.)
- rechinist has prepared \(B\) types of prizes. For each prize type he set, the prize must be given to an odd number of winners (and since 0 is not odd, each of these prizes must be used).
Every winning contestant will receive exactly one prize. Note that the committees can distribute extra copies of a prize as long as the parity condition remains preserved; that is, after giving the minimal required number (1 for each rechinist prize and 2 for each used uuku prize) extra winners (in multiples of 2) may be added arbitrarily.
The enthusiasm of the contestants is defined as the product of the values of each type of prize that is actually awarded (each prize type is multiplied once regardless of how many copies are given). For uuku’s prizes, the value of the \(i\)th prize is \(a_i\); for rechinist’s prizes, the value of the \(j\)th prize is \(b_j\). If for a certain number of winners the committees cannot distribute the prizes according to the rules, the awards are canceled and the enthusiasm is 0.
Suppose that the number of winners is \(k\). Since every rechinist prize must be used, we must have \(k\ge B\). Moreover, extra winners beyond the compulsory \(B\) (each rechinist prize getting its minimal count of \(1\)) can be used to optionally award some of uuku's prizes: if one decides to use a uuku prize then it must be given to an even number (at least 2) of winners. Hence, if we select a subset \(S\) of uuku's prizes (of size \(|S|\)) to use, we need at least \(B+2|S|\) winners, and extra winners can always be allocated (in even increments) without affecting the product. Since the contestants care only about which prize types are awarded, the final enthusiasm is the product of
- all rechinist prizes \(\bigl(\prod_{j=1}^{B} b_j\bigr)\) (these are mandatory), and
- the selected uuku prizes \(\prod_{i\in S} a_i\).
For a given \(k\ge B\), one can choose any subset of uuku prizes with \(|S|\le \lfloor (k-B)/2 \rfloor\). To maximize the enthusiasm (and hence the expectation), the committees will choose the subset \(S\) that yields the maximum product \(\prod_{i\in S} a_i\). In particular, if we sort uuku's prize values in descending order, the optimal choice is to take the first \(r\) prizes where \(r = \min\Bigl(A, \lfloor (k-B)/2 \rfloor \Bigr)\.
Your task is to compute, over the randomness of winners (each contestant wins independently with probability \(p_i\)), the expected value of the contestants' enthusiasm modulo \(998244353\). If for a given outcome the prize distribution is impossible (i.e. \(k < B\)), then the enthusiasm is \(0\).
Input and Output are described below.
inputFormat
The first line contains three integers \(n\), \(A\) and \(B\) (n is the number of contestants, \(A\) the number of prizes set by uuku, and \(B\) the number of prizes set by rechinist).
The second line contains \(n\) real numbers \(p_1, p_2, \ldots, p_n\) separated by spaces, where \(p_i\) is the probability that the \(i\)th contestant reaches the score‐line. It is guaranteed that each \(p_i\) has at most 6 digits after the decimal point.
The third line contains \(A\) positive integers \(a_1, a_2, \ldots, a_A\) separated by spaces, representing the values of uuku's prizes.
The fourth line contains \(B\) positive integers \(b_1, b_2, \ldots, b_B\) separated by spaces, representing the values of rechinist's prizes.
outputFormat
Output a single integer: the expected enthusiasm value modulo \(998244353\).
sample
3 1 1
0.5 0.5 0.5
2
3
3
</p>