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

#PS0000126. Kỳ vọng lớn nhất của dãy xúc xắc (Dice in Line)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Kỳ vọng lớn nhất của dãy xúc xắc (Dice in Line)

Dice in Line

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Arrange NN dice in a row. Die ii produces an integer from 11 through pip_i, each with equal probability. Select exactly KK consecutive dice and roll them independently. Determine the largest possible expected sum of the results. An expectation is the probability-weighted average of the possible outcomes.

Input

The first line contains integers N,KN,K, the number of dice and the number to select.

The second line contains NN integers p1,…,pNp_1,\ldots,p_N, the number of possible outcomes on each die.

Output

Print one real number: the maximum expectation. An absolute or relative error of at most 10−610^{-6} is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤K≤N≤10001\le K\le N\le1000; 1≤pi≤10001\le p_i\le1000 for every 1≤i≤N1\le i\le N.
  • Subtask 2 (30 points): 1≤K≤min⁡(N,10)1\le K\le\min(N,10); 1≤N≤2000001\le N\le200000; 1≤pi≤10001\le p_i\le1000 for every 1≤i≤N1\le i\le N.
  • Subtask 3 (50 points): 1≤K≤N≤2000001\le K\le N\le200000; 1≤pi≤10001\le p_i\le1000 for every 1≤i≤N1\le i\le N.

Example 1

Input

5 3
1 2 2 4 5

Output

7.000000000000

Explanation

The three windows have expectations 44, 5.55.5 and 77: the last is 1.5+2.5+3=71.5+2.5+3=7, the largest.

Example 2

Input

4 1
6 6 6 6

Output

3.500000000000

Explanation

Each die has expectation (1+2+3+4+5+6)/6=3.5(1+2+3+4+5+6)/6=3.5. Every single-die choice attains it.

Example 3

Input

10 4
17 13 13 12 15 20 10 13 17 11

Output

32.000000000000

Explanation

The seven windows have face-count sums 55, 53, 60, 57, 58, 60, 51. Their expectations are (S+4)/2(S+4)/2; both windows with S=60S=60 attain 32.