Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Announcement
Problems
Submit Problem
Status (Online)
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID: 
Password:
  Register

Expected Difference
Time Limit:1000MS  Memory Limit:131072K
Total Submit:681 Accepted:163

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 12 probability to obtain a difference of 1, 13 probability of 2 and 16 probability of 3. So the answer is 12 ¡Á 1 + 13 ¡Á 2 + 16 ¡Á 3, which is equal to 53 ¡Ö 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.

Sample Input

2 2
1 2
3 2
1 2 3
4 2
1 2 3 4
4 3
2 3 8 9
0 0

Sample Output

1.000
1.333
1.667
6.500

Source
POJ Monthly--2006.09.29, ACRush

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


All Copyright Reserved 2003-2005 Ying Fuchen,Xu Pengcheng
Any problem, Please Contact Administrator