#P1721. [NOI2016] 国王饮水记

    ID: 684 远端评测题 2000ms 250MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划,dp2016NOI 系列Special Judge斜率优化

[NOI2016] 国王饮水记

Description

The Flea Kingdom has nn cities. The great Flea King lives in the capital of the Flea Kingdom, that is, in city 11.

The biggest problem in the Flea Kingdom is drinking water. Because too many fleas live in the capital, and the kind Flea King also gives the water allocated to him to the residents, the Flea King often cannot get water to drink.

Therefore, the Flea Kingdom built a cylindrical water tank in every city. These tanks are completely identical and tall enough. After a rainy day, city ii collected water with height hih_i. Due to geographic and weather factors, the water heights collected by any two different cities are all distinct.

The Flea King also invited ant craftsmen to help build a large underground connecting system. Each time the Flea King uses the underground connecting system, he can specify any number of cities, connect the tanks of these cities with the underground system for a sufficiently long time, and then turn the system off. By the principle of communicating vessels, after this operation the water in those cities’ tanks will reach the same height, and this height equals the average of the specified tanks’ heights.

Because of the complexity of the underground system, the Flea King can use it at most kk times.

Please tell the Flea King: how high can the water level in the capital’s tank (city 11) be at most?

Input Format

The first line contains three positive integers n,k,pn,k,p, representing the number of cities in the Flea Kingdom, the maximum number of times the Flea King can use the underground connecting system, and the required precision of your output. The meaning of pp is explained in the Output Format.

The next line contains nn positive integers describing the water levels in the cities’ tanks after the rain. The ii-th integer hih_i is the water level in city ii’s tank. It is guaranteed that the hih_i are pairwise distinct, and 1hi1051 \leq h_i \leq 10^5.

Output Format

Output a single real number, the maximum possible water level in city 11’s tank.

This real number may contain only a non-negative integer part, a decimal point, and a fractional part. The non-negative integer part is required and should not have a sign. If there is a fractional part, separate it from the integer part with one decimal point; if there is no fractional part, do not print a decimal point.

The number of digits after the decimal point must not exceed 2p2p. It is recommended to keep at least pp digits. It is guaranteed that the absolute error between the reference answer and the true answer is less than 102p10^{-2p}.

Your output is judged correct if and only if its absolute error with the reference answer is less than 10p10^{-p}.

If the absolute error of your output is not less than 10p10^{-p} but less than 10510^{-5}, you can receive 40%40\% of the score for that test point.

3 1 3
1 4 3
2.666667
3 2 3
1 4 3
3.000000

Hint

Sample Explanation 1

Since the underground connecting system can be used at most once, there are the following five options:

  1. Do not use the underground system: the water level in city 11’s tank is 11.
  2. Use the system once to connect cities 11 and 22: the water level in city 11’s tank is 5/25/2.
  3. Use the system once to connect cities 11 and 33: the water level in city 11’s tank is 22.
  4. Use the system once to connect cities 22 and 33: the water level in city 11’s tank is 11.
  5. Use the system once to connect cities 1,2,31,2,3: the water level in city 11’s tank is 8/38/3.

Sample Explanation 2

The optimal plan is to use the system twice: first connect cities 11 and 33, then connect cities 11 and 22.

Sample 3

See the attached file.

Hint

To ensure precision, we generally need to keep more than pp decimal digits during computation. We can prove that in the reference solutions for all sub-tasks, if we always keep 65p\frac{6}{5}p decimal digits at any time, then for any input the absolute error of the output will be less than 10p10^{-p}.

To make it easier to handle high-precision decimals, we provide a fixed-point high-precision decimal class. Contestants may refer to and use this class as needed, or choose not to use it. For specific usage, please refer to the distributed document decimal.pdf (see the attachment).

Constraints

::cute-table{tuack}

Test Point nn kk pp
1 2\le 2 5\le 5 =5=5
22 4\le 4 ^ ^
33 ^
4 10\le 10 =1=1
55 ^ =109=10^9
66 10\le 10
77 ^
88 100\le 100 =1=1
99 ^ =109=10^9 =40=40
1010 109\le 10^9 ^
1111 ^
1212
1313 250\le 250 =100=100
1414 500\le 500 =200=200
1515 700\le 700 =300=300
1616 ^ ^
1717
1818 2500\le 2500 =1000=1000
1919 4000\le 4000 =1500=1500
2020 8000\le 8000 =3000=3000

Translated by ChatGPT 5