Another Expected Value Problem

시간 제한1초메모리 제한2048 MB

요약
무작위로 원소를 골라 나머지를 한 칸씩 끌어당기는 연산을 k번 수행한 뒤 무작위 원소의 기댓값을 1e9+7로 나눈 나머지로 구한다.
난이도

어려움10점 중 8점

유형
수학, 확률, 조합론, 누적 합
정답자
아직 제출이 없습니다

문제

You are given an array aa of nn integers. You then perform the following process kk times.

  • Choose an integer ii where 1≤i≤n1 \le i \le n, uniformly at random.

  • For each 1≤j≤n1 \le j \le n, move a_ja\_j one unit closer to a_ia\_i. Formally, for each jj,

    • If a_j<a_ia\_j < a\_i, increment a_ja\_j by 11
    • If a_j>a_ia\_j > a\_i, decrement a_ja\_j by 11
    • If a_j=a_ia\_j = a\_i, do not modify the value of a_ja\_j.

After performing this process kk times, you select an integer ii where 1≤i≤n1 \le i \le n uniformly at random. What is the expected value of a_ia\_i?

It can be shown that this value can be represented as PQ\frac{P}{Q} where PP and QQ are coprime integers and Q≢0mod  109+7Q \not\equiv 0 \mod 10^9+7. Print the value of P⋅Q−1P\cdot Q^{-1} modulo 109+710^9+7.

입력

The first line of the input contains a single integer tt (1≤t≤1041\le t\le 10^4) --- the number of test cases.

The first line of each test case contains two integers nn and kk (1≤n,k≤2⋅1051\le n,k \le 2\cdot 10^5) --- the length of the array and the number of operations you will perform.

The second line of each test case will contain nn integers a_1,a_2,⋯a_na\_1, a\_2, \cdots a\_n (1≤a_i≤1091 \le a\_i \le 10^9) --- the initial array aa.

It is guaranteed that the sum of nn over all test cases, and the sum of kk over all test cases, do not exceed 2⋅1052\cdot 10^5.

출력

For each test case, output a single line containing the expected value of a_ia\_i at the end of this process, modulo 109+710^9+7 as described above.

힌트

In the first sample case, since all elements of aa are initially equal, none of them will change after any of the k=5k=5 operations. Therefore, the final array will be \[8,8,8]\[8, 8, 8], so the expected value of a random element of the final array is 88.

In the second sample case, there is a 5050\\% chance of choosing i=1i = 1 in the operation, and a 5050\\% chance of choosing i=2i = 2.

  1. If i=1i = 1 is chosen, all elements of the array will move closer to a_1=10a\_1 = 10, so aa will go from \[10,11]\[10, 11] to \[10,10]\[10, 10]. The expected value of a random element of this array is 1010.
  2. If i=2i = 2 is chosen, all elements of the array will move closer to a_2=11a\_2 = 11, so aa will go from \[10,11]\[10, 11] to \[11,11]\[11, 11]. The expected value of a random element of this array is 1111.

So there is a 5050\\% chance of the expected value being 1010, and a 5050\\% chance of it being 1111. Therefore, the final expected value is 10.5=21210.5 = \frac{21}{2}, which is equivalent to 50000000145000000014 modulo 109+710^9+7.

예제1

  1. 예제 1

    입력
    3
    3 5
    8 8 8
    2 1
    10 11
    7 7
    9 8 7 6 5 4 2
    
    예상 출력
    8
    500000014
    857142869