#abc341g. G - Highest Ratio

G - Highest Ratio

Score: 575575 points

问题描述

你已知一个长度为 NN 的序列 A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N)。对于每个 k=1,2,,Nk=1,2,\ldots,N,解决以下问题:

  • 找出当选择满足 krNk\leq r\leq N 的整数 rr 时,序列 AA 中从第 kk 项到第 rr 项可能的最大平均值。
    • 在这里,序列 AA 中从第 kk 项到第 rr 项的平均值定义为 1rk+1i=krAi\frac{1}{r-k+1}\displaystyle\sum_{i=k}^r A_i

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) of length NN.
For each k=1,2,,Nk=1,2,\ldots,N, solve the following problem:

  • Find the maximum possible average value of the kk-th to rr-th terms of the sequence AA when choosing an integer rr such that krNk\leq r\leq N.
    Here, the average value of the kk-th to rr-th term of the sequence AA is defined as 1rk+1i=krAi\frac{1}{r-k+1}\displaystyle\sum_{i=k}^r A_i.

Constraints

  • 1N2×1051\leq N\leq 2\times 10^5
  • 1Ai1061\leq A_i\leq 10^6
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

Output

Print NN lines.
The ii-th line (1iN)(1\leq i\leq N) should contain the answer to the problem for k=ik=i.
Your output will be considered correct if, for every line, the absolute or relative error of the printed value from the true value is at most 10610^{-6}.

Sample Input 1

5
1 1 4 5 3

Sample Output 1

2.80000000
3.33333333
4.50000000
5.00000000
3.00000000

For k=1k=1, the possible choices for rr are r=1,2,3,4,5r=1,2,3,4,5, and the average value for each of them is:

  • 11=1\frac{1}{1}=1
  • 12(1+1)=1\frac{1}{2}(1+1)=1
  • 13(1+1+4)=2\frac{1}{3}(1+1+4)=2
  • 14(1+1+4+5)=2.75\frac{1}{4}(1+1+4+5)=2.75
  • 15(1+1+4+5+3)=2.8\frac{1}{5}(1+1+4+5+3)=2.8

Thus, the maximum is achieved when r=5r=5, and the answer for k=1k=1 is 2.82.8.
Similarly, for k=2,3,4,5k=2,3,4,5, the maximum is achieved when r=4,4,4,5r=4,4,4,5, respectively, with the values of 103=3.333\frac{10}{3}=3.333\ldots, 92=4.5\frac{9}{2}=4.5, 51=5\frac{5}{1}=5, 31=3\frac{3}{1}=3.

Sample Input 2

3
999999 1 1000000

Sample Output 2

999999.00000000
500000.50000000
1000000.00000000

update @ 2024/3/10 01:35:37