#P14805. [CCPC 2024 哈尔滨站] 弹珠赛跑
[CCPC 2024 哈尔滨站] 弹珠赛跑
Description
Marble race is a fun way to play with marbles, and today you want to give it a try.
There are starting points on the negative half of the -axis, with the -th point located at . There are marbles in total, where is an odd number, and the -th marble has a speed of . In a race, each marble randomly chooses a starting point with equal probability, and different marbles can choose the same starting point. Then, all the marbles start moving simultaneously towards the positive direction of the -axis. Let be the starting point chosen by the -th marble. At time , the coordinate of the -th marble is given by .
You are a unique marble race enthusiast and do not care which marble is the fastest. Instead, you want to find out the exact time when the \textbf{median} of all the marble coordinates reaches the origin (i.e., ). The median of a sequence of length (where is odd) is defined as the element at the position when sorted in ascending order (indexing starts from ). Since the race has not yet started and the starting points are not yet determined, you are interested in the expected value of this time. To avoid floating-point errors, you only need to output the result modulo (see the output format for details).
Input Format
The first line contains two positive integers and (, and is odd), representing the number of starting points and the number of marbles.
The second line contains integers (), representing the coordinates of each starting point. It is guaranteed that all are distinct.
The third line contains integers (), representing the speed of each marble.
Output Format
Output a single integer, representing the expected time modulo .
Formally, let . It can be shown that the answer can be expressed as an irreducible fraction , where and are integers and . Output the integer equal to , where denotes the modular multiplicative inverse of modulo . In other words, output such an integer that and . It can be proved that there is exactly one which meets the condition.
2 3
-4 -5
1 2 3
250000004
3 3
-4 -5 -6
1 2 3
500000006
5 5
-4 -5 -6 -10 -2
1 2 3 2 4
434986672
Hint
For the first example, the speeds of the three marbles are , respectively. Consider the initial positions of the three marbles:
- : At , the coordinates of the three marbles are , and the median is at the origin.
- : At , the coordinates are , and the median is at the origin.
- : At , the coordinates are , and the median is at the origin.
- For , , , , , the median is at the origin at times , , , , , respectively.
In summary, the expected time is $\frac{2 + 2 + 2.5 + 2.5 + 2 + 2 + 2.5 + 2.5}{8} = \frac{9}{4}$, so you need to output .
京公网安备 11011102002149号