#PS0000126. Kỳ vọng lớn nhất của dãy xúc xắc (Dice in Line)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 dice in a row. Die produces an integer from through , each with equal probability. Select exactly 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 , the number of dice and the number to select.
The second line contains integers , the number of possible outcomes on each die.
Output
Print one real number: the maximum expectation. An absolute or relative error of at most is accepted.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; for every .
Example 1
Input
5 3
1 2 2 4 5
Output
7.000000000000
Explanation
The three windows have expectations , and : the last is , the largest.
Example 2
Input
4 1
6 6 6 6
Output
3.500000000000
Explanation
Each die has expectation . 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 ; both windows with attain 32.