#C7526. Average Floor Height Calculation

    ID: 51407 Type: Default 1000ms 256MiB

Average Floor Height Calculation

Average Floor Height Calculation

In this problem, you are given the heights of N floors in a building. Due to construction constraints, each floor can have a different height. You are also given Q queries where each query specifies a range of floors; your task is to calculate the average height for the floors in the given range. The average should be computed using the formula:

[ \text{average} = \frac{\sum_{i=L}^{R} \text{height}_i}{R - L + 1} ]

Each result must be printed with exactly two digits after the decimal point.

For example, if the building has 5 floors with heights [3, 9, 4, 2, 8] and the query is (1, 3), then the answer is computed as (\frac{3+9+4}{3} = 5.33).

inputFormat

The input is read from standard input (stdin) and has the following format:

The first line contains two space-separated integers, N and Q, representing the number of floors and the number of queries.

The second line contains N space-separated integers representing the heights of the floors.

The following Q lines each contain two space-separated integers L and R, representing a query for the range of floors from L to R (inclusive). Note that the floors are 1-indexed.

outputFormat

For each query, print the average height of the specified range of floors on a new line with exactly two digits after the decimal point. The output should be written to standard output (stdout).## sample

5 3
3 9 4 2 8
1 3
2 5
1 5
5.33

5.75 5.20

</p>