No.576 E869120 and Rings
タグ : / 解いたユーザー数 24
作問者 :
e869120
/ テスター :
Problem Statement
E869120 received a ring. This ring consists of $N$ gems arranged in a circle.
Each gem is either blue or red.
E869120 has decided to take out a contiguous part of the ring. This part must consist of at least $K$ gems.
Find the maximum possible proportion of "blue gems" within the "part of the ring" taken out.
Input
$N$ $K$ $a_1$$a_2$...$a_N$
- $1≦K≦N≦500000$
- $0≦a_i≦1$
- $a_i=0$ means red, and $a_i=1$ means blue
Output
Output the maximum proportion of blue as a decimal. An error of up to $10^{-6}$ is allowed. Print a newline at the end.
Sample
Sample 1
Input
8 4 11101110
Output
0.857142857142857
The gems are arranged as follows.

In this case, taking gems 1, 2, 3, 4, 5, 6, 7 gives $6$ blue gems and $1$ red gem.
The proportion is then $6 / 7$ ≒ $0.857142857...$.
Note that, for example, taking gems 5, 6, 7 would make the proportion of blue $100$%, but since $K=4$, you must take at least $4$ gems.
Sample 2
Input
8 4 11011001
Output
0.833333333333333
Take out the interval [8, 5] (that is, gems {8, 1, 2, 3, 4, 5}).
Then the proportion of blue is $5 / 6$ ≒ $0.833333333...$.
Sample 3
Input
10 4 1001001001
Output
0.6
Take out the interval [10, 4] (that is, gems {10, 1, 2, 3, 4}).
The interval [7, 1] also achieves the same proportion.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。