#P3015. Expected Difference
Expected Difference
Description
Given n distinct integer numbers A = { A1, A2, …, An } and an integer m, then choose m distinct elements B = { B1, B2, …, Bm } randomly from A. You are to calculate the expected difference between the largest and smallest number of B.
For example, consider the case where n = 4, m = 2, and A = { 1, 2, 3, 4 }. It has 1⁄2 probability to obtain a difference of 1, 1⁄3 probability of 2 and 1⁄6 probability of 3. So the answer is 1⁄2 × 1 + 1⁄3 × 2 + 1⁄6 × 3, which is equal to 5⁄3 ≈ 1.667.
Input
The input contains multiple test cases.
Each test case contains consists of two lines. The first line gives the integers n (2 ≤ n ≤ 50 000) and m (2 ≤ m ≤ n). The second line gives n distinct integers A1, A2, …, An. (0 ≤ Ai ≤ 65 536), which will be sorted in increasing order.
A pair of zeroes indicates the end of the input and should not be processed.
Output
Output the answer of each test case on a separate line with the fraction rounded to 3 decimal places.
2 2
1 2
3 2
1 2 3
4 2
1 2 3 4
4 3
2 3 8 9
0 0
1.000
1.333
1.667
6.500
Source
POJ Monthly--2006.09.29, ACRush