ZOJ-2091-Mean of Subsequence

Given N numbers in a line, we can determine a continuous subsequence by giving its start position and its length.
PMH and Roy played a game the other day. Roy gives the start position first, then PMH gives the length. Roy wants the mean of the subsequence as large as possible, while PMH wants it as small as possible.

You are to calculate the best result Roy can get, assuming PMH is very clever.


Input

There are multiple testcases.

Each testcase begins with a line containing N only.

The following line contains N numbers, separated by spaces.


Output

For each testcase, you are to print the best mean of subsequece Roy can get, precise to 6 digit after decimal point.


Sample Input

10
2 10 4 6 5 10 10 2 3 2


Sample Output

5.777778

其实就是找后k个数的平均值的最大值  k=1,2,3……n ,记做kmax

因为一旦Roy选了这个kmax,PMH必定会将所选数字长度最大化

用反证法证明:如果所选长度的最后一个数字不是n  而是kmax与n中间的某个数t

那么也就是说ave(kmax...t)<ave(kmax...n)

那么必有 ave(t+1...n)>ave(kmax...n)   说明最后t+1个数的平均数最大 与题设矛盾

Mean of Subsequence

 

posted @ 2009-05-30 00:53  ziroy  Views(268)  Comments(0)    收藏  举报