PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000398. Trung bình đoạn con lớn nhất II (Maximum Average Subarray II)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Trung bình đoạn con lớn nhất II (Maximum Average Subarray II)

Maximum Average Subarray II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer sequence a1,a2,…,ana_1,a_2,\ldots,a_n and an integer kk, choose a contiguous segment from index ll through index rr, where 1≤l≤r≤n1\le l\le r\le n and r−l+1≥kr-l+1\ge k.

The average of the selected segment is

∑i=lrair−l+1.\frac{\sum_{i=l}^{r}a_i}{r-l+1}.

Determine the greatest average over all valid segments. Values may be negative; no element between the two endpoints may be skipped.

Input

  • The first line contains two integers n,kn,k: the sequence length and the minimum segment length.
  • The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in sequence order.

Output

Print one real number equal to the maximum average. The absolute error must be strictly less than 10−510^{-5}.

Subtasks

  • Subtask 1 (20 points): 1=k≤n≤1041=k\le n\le10^4; −104≤ai≤104-10^4\le a_i\le10^4 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤k≤n≤5001\le k\le n\le500; −104≤ai≤104-10^4\le a_i\le10^4 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤k≤n≤1041\le k\le n\le10^4; −104≤ai≤104-10^4\le a_i\le10^4 for every 1≤i≤n1\le i\le n.

Examples

Input

6 4
1 12 -5 -6 50 3

Output

12.7500000000

Explanation

The three length-4 sums are 2, 51 and 42, giving averages 0.5, 12.75 and 10.5. Length-5 sums are 52 and 54, giving 10.4 and 10.8. The full sequence averages 55/6. The maximum is 12.75, at indices 2 through 5.

Input

3 2
9 -10 9

Output

2.6666666667

Explanation

Both length-2 segments sum to -1 and average -0.5. The length-3 segment sums to 8 and averages 8/38/3, which is larger.

Input

1 1
-10000

Output

-10000.0000000000

Explanation

The only eligible segment contains -10000, so its average is -10000.

Input

1 1
5

Output

5.0000000000

Explanation

There is one element, 5, and the minimum length is 1. The only eligible segment has sum 5 and length 1, giving the maximum average 5/1=55/1=5.