Logo
(追記) (追記ここまで)

29903번 - Lottery 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB148866.667%

문제

Jack spends a lot of time and money playing the lottery.

The lottery machine consists of $N$ parallel ramps (as shown on the figure). Each ramp is divided into $M$ sections of equal lengths. Under the ramps are $M$ baskets, each labeled with an integer.

The drawing works as follows. First some ramp sections from among the $N \cdot M$ are removed. For each section, a $B$-sided die (with the sides numbered 1,ドル \ldots, B$) is rolled and if the result is at most $A,ドル the section is removed. After that, a ball is released from the top-left corner of the machine, above the topmost ramp. If the ball ends up in a basket, the player's prize is the amount written on the basket.

You try to explain to Jack that in general, he always loses money in such games. To prove your point, you want to compute the expected average value of the prize of this game.

It can be shown that the expected value can be expressed as $\frac{p}{q}$ where $p$ and $q$ are integers and $\frac{p}{q}$ is an irreducible fraction. Compute the value $pr \bmod (10^9 + 7)$ where $r$ is such an integer that $qr \bmod (10^9 + 7) = 1$.

입력

The first line contains space-separated integers $N$ and $M$ (2ドル \le N, M \le 5 \cdot 10^5$), the dimensions of the lottery machine. The second line contains space-separated integers $A$ and $B$ (0ドル \le A \le B < 10^9 + 7,ドル $B \ne 0$), the parameters of the die rolls.

The third line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$ (0ドル \le C_i \le 10^9$ for each $i$), the values of the baskets from left to right.

출력

Output a single integer: the expected value of Jack's prize, in the format described above.

제한

예제 입력 1

2 2
1 2
10 100

예제 출력 1

500000031

예제 입력 2

2 4
2 5
1 2 3 4

예제 출력 2

483520005

예제 입력 3

3 3
0 1
1 2 3

예제 출력 3

0

예제 입력 4

3 3
1 1
1 2 3

예제 출력 4

1

예제 입력 5

8 6
17536540 365964399
49 8 28 51 32 24

예제 출력 5

214402328

노트

To format your output in this task, you need to compute $r$ such that $qr \equiv 1 \pmod{K}$ (in our case, $K = 10^9 + 7$). This number is called the inverse of $q$ modulo $K$; it can be shown that if $q \not\equiv 0 \pmod{K}$ and $K$ is prime, then $r$ can be computed as $r = q^{K - 2} \bmod K$.

출처

Olympiad > Estonian Informatics Olympiad > 2020-21 > Final Round 4번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /