| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12139 | HA HA HA |
|
| 12135 | Ghoul Dawn |
|
Description
There are n children in Johnny Johnny' s family.
And number i child wants to have ai units of sugar.
But their PaPa don't want them eat too much sugar. Therefore he will randomly choose some children and only give them the great common divisor of ai.
For example, if there're n=5 children and ai = { 1, 4, 6, 7, 18 }.
Suppose PaPa choose the children numbered 2,3,5.
Then all children will only get gcd(a2, a3, a5) = gcd(4,6,18) = 2 unit of sugar.
Now Johnny wants to know what's the maximum amount of sugar they can get.(PaPa will at least choose two child)
If you can help him, he will laugh at you for you don't have any sugar " Ha Ha Ha!!! "
To calculate great common divisor, you can use the method 輾轉相除法(https://zh.wikipedia.org/wiki/%E8%BC%BE%E8%BD%89%E7%9B%B8%E9%99%A4%E6%B3%95)
Input
input contains two lines.
First line only contains one integer n ( 2 <= n <= 1000)
Second line contain n integers a1 ~ an ( 1<= ai <= 1000 )
Output
output contains only one integer the maximum amount of sugar they can get.
remember to print \n at the end of output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
A famous streamer once said: " How dare you come down!! Ice Bird!! ", This famous streamer is also known as " Ghoul Dawn ". After killed the Ice Bird, Ghoul Dawn strart to kill little soldiers.
There're n soldiers in front of Ghoul Dawn, their HP are denote as a1 ~ an .
Ghoul Dawn's attack can attack at least k soldier at once but must be continuous segment of soldiers.
The damage Ghoul Dawn can make is the sum of soldiers' HP.
Ghoul Dawn wants to know the maximum average damage(the sum of soldiers' HP divided by the number of soldiers ) he can make.
For example:
There are n=5 soldiers, and a1~an = { 5,9,6,10,3 }.
Ghoul Dawn can attack k =2 soldiers at once.
He can kill either { 5,9 } or { 9,6,10 } or { 5,9,6,10,3 }..... . He need to choose { 9,6,10 } because (9+6+10)/3 is the maximum average damage he can make.
Help Ghoul Dawn find out what's the maximum average damage he can make at once. Output the number to three decimal places.
If you help him, he will tell you how to "Slide up".
⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠈⠉⠁⠈⠉⠉⠙⠿⣿⣿⣿⣿⣿
⠄⠄⠄⠄⠄⠄⠄⠄⣀⣀⣀⠄⠄⠄⠄⠄⠹⣿⣿⣿
⠄⠄⠄⠄⠄⢐⣲⣿⣿⣯⠭⠉⠙⠲⣄⡀⠄⠈⢿⣿
⠐⠄⠄⠰⠒⠚⢩⣉⠼⡟⠙⠛⠿⡟⣤⡳⡀⠄⠄⢻
⠄⠄⢀⣀⣀⣢⣶⣿⣦⣭⣤⣭⣵⣶⣿⣿⣏⠄⠄⣿
⠄⣼⣿⣿⣿⡉⣿⣀⣽⣸⣿⣿⣿⣿⣿⣿⣿⡆⣀⣿
⢠⣿⣿⣿⠿⠟⠛⠻⢿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣼
⠄⣿⣿⣿⡆⠄⠄⠄⠄⠳⡈⣿⣿⣿⣿⣿⣿⣿⣿⣿
⠄⢹⣿⣿⡇⠄⠄⠄⠄⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⠄⠄⢿⣿⣷⣨⣽⣭⢁⣡⣿⣿⠟⣩⣿⣿⣿⠿⠿⠟
⠄⠄⠈⡍⠻⣿⣿⣿⣿⠟⠋⢁⣼⠿⠋⠉⠄⠄⠄⠄
⠄⠄⠄⠈⠴⢬⣙⣛⡥⠴⠂⠄⠄⠄⠄⠄⠄⠄⠄⠄...
(the photo of the famous streamer)
HINT: You can use the method "prefix sum(https://en.wikipedia.org/wiki/Prefix_sum)" to solve this question.
Input
input contains two lines.
First line contains two integer n, k( 1<= k <= n <= 5000 )
Second contains n integer a1~an( 1<= ai <= 109 )
Output
output only contains one integer -- the maximum average damage Ghoul Dawn can make. Output the number to three decimal places.
remember to print \n at the end of output.