103416: [Atcoder]ABC341 G - Highest Ratio

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score: $575$ points

Problem Statement

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

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

Constraints

  • $1\leq N\leq 2\times 10^5$
  • $1\leq A_i\leq 10^6$
  • All input values are integers.

Input

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

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

Output

Print $N$ lines.
The $i$-th line $(1\leq i\leq N)$ should contain the answer to the problem for $k=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 $10^{-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=1$, the possible choices for $r$ are $r=1,2,3,4,5$, and the average value for each of them is:

  • $\frac{1}{1}=1$
  • $\frac{1}{2}(1+1)=1$
  • $\frac{1}{3}(1+1+4)=2$
  • $\frac{1}{4}(1+1+4+5)=2.75$
  • $\frac{1}{5}(1+1+4+5+3)=2.8$

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


Sample Input 2

3
999999 1 1000000

Sample Output 2

999999.00000000
500000.50000000
1000000.00000000

Input

Output

分数:575分

问题描述

给你一个长度为 $N$ 的序列 $A=(A_1,A_2,\ldots,A_N)$。
对于每个 $k=1,2,\ldots,N$,解决以下问题:

  • 找到序列 $A$ 中第 $k$ 项到第 $r$ 项的可能的最大平均值,选择一个满足 $k\leq r\leq N$ 的整数 $r$。在这里,序列 $A$ 中第 $k$ 项到第 $r$ 项的平均值定义为 $\frac{1}{r-k+1}\displaystyle\sum_{i=k}^r A_i$。

约束

  • $1\leq N\leq 2\times 10^5$
  • $1\leq A_i\leq 10^6$
  • 所有的输入值都是整数。

输入

输入从标准输入按以下格式给出:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$

输出

打印 $N$ 行。
第 $i$ 行 $(1\leq i\leq N)$ 应包含 $k=i$ 时问题的答案。
如果你的输出满足以下条件,将被认为是正确的:对于每一行,打印值与真实值之间的绝对或相对误差不超过 $10^{-6}$。


样例输入 1

5
1 1 4 5 3

样例输出 1

2.80000000
3.33333333
4.50000000
5.00000000
3.00000000

对于 $k=1$,可能的 $r$ 值为 $r=1,2,3,4,5$,它们对应的平均值分别为:

  • $\frac{1}{1}=1$
  • $\frac{1}{2}(1+1)=1$
  • $\frac{1}{3}(1+1+4)=2$
  • $\frac{1}{4}(1+1+4+5)=2.75$
  • $\frac{1}{5}(1+1+4+5+3)=2.8$

因此,当 $r=5$ 时,最大值达到,$k=1$ 时的答案为 $2.8$。
类似地,对于 $k=2,3,4,5$,最大值分别在 $r=4,4,4,5$ 时达到,对应的值分别为 $\frac{10}{3}=3.333\ldots$,$\frac{9}{2}=4.5$,$\frac{5}{1}=5$,$\frac{3}{1}=3$。


样例输入 2

3
999999 1 1000000

样例输出 2

999999.00000000
500000.50000000
1000000.00000000

加入题单

算法标签: