Average of the branch sales indexes
Statement
A franchise head office collected last month's sales of N branches. The branches differ in size, so weighing the sales against each other directly is hard. The head office therefore turns the sales into indexes.
An index is built as follows. First, let M be the largest value among the sales of the N branches. When a branch has sales S, the index of that branch is S divided by M, times 100. This way the index of the branch with the largest sales is always 100, and the index of every other branch is a value smaller than 100. The index of a branch with sales of 0 is 0. An index goes through a division, so it is usually a fraction. With indexes, the best-selling branch sits at 100 and every other branch can be weighed by how close it comes to that, whatever the size of the branch.
The head office wants to write the average of these N converted indexes in a report. The average is the sum of the N indexes divided by N. The indexes are added in order of branch number, from branch 1 to branch N. The indexes are fractions, so a different order of addition can throw off a very small decimal place.
Given the sales of the N branches, write a program that prints the average of the converted indexes.
For example, suppose the sales of N=3 branches are 72, 84, and 51 in order. The largest value is 84, so M is 84. Working out the index of each branch gives the table below. In the table, a value with many decimal places is written only to four decimal places.
| Branch number | 1 | 2 | 3 |
|---|---|---|---|
| Sales | 72 | 84 | 51 |
| Index | 85.7143 | 100 | 60.7143 |
Branch 2 has the largest sales, so its index came out as 100. The index of branch 1 is 72 divided by 84, times 100, and the index of branch 3 is 51 divided by 84, times 100. Adding the three indexes gives about 246.4286, and dividing that by 3 gives an average of about 82.1428. The answer is this value written exactly as it was worked out, with no decimal places padded and no rounding.
If there is only one branch, that branch is the one with the largest sales, so its index is 100 and the average is 100 as well. When every branch has the same sales, every index is 100 and the average is 100.
Input and Output Examples
Example 1
Input
3 72 84 51
Output
82.14285714285715
Example 2
Input
1 100
Output
100
Example 3
Input
2 69 86
Output
90.11627906976744
Input
First, the number of branches N is given on the first line. N is a natural number between 1 and 1,000.
Next, the second line gives the sales of the N branches in order of branch number, separated by spaces. Each sales figure is an integer between 0 and 100. Also, at least one of the N sales figures is greater than 0. So M, the base of the conversion, is always greater than 0, and no division by zero happens.
Output
Print the average of the converted indexes on one line. Write the value exactly as it was worked out, with no decimal places padded and no rounding. If the average is 100, write 100, and if a fractional part is left, write it out without cutting any places. For example, with two branches whose sales are 69 and 86, write 90.11627906976744.
Requirements
- Read the input from standard input and write the answer to standard output
- M, the base of the conversion, is the largest of the sales figures. It is not the sum and not the average
- Convert each sales figure on its own, and then take the average of the converted values
- Add the indexes in order of branch number, starting at branch 1. Changing the order, or correcting the error as you add, can throw off the last decimal place
- Rounding the value or padding the decimal places gives a wrong answer. You must write out the floating-point result as it is
- Grading compares the output with the expected value down to the last character
- You must write a program that reads from standard input and writes to standard output
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 15 cases to solve this.
Examples
3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.
1 100
100
2 69 86
90.11627906976744
3 72 84 51
82.14285714285715
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 3 public cases. Submitting runs the hidden cases too.
People who solved this problem
The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.
Log in and you can see the code once you solve this problem.