Drinking Water
Time limit2sMemory limit1024 MB
Given n distinct values and up to k averaging operations on chosen subsets, find the maximum value h_1 can reach, printed to p decimal digits.
- Level
Hard9 of 10
- Topics
- Binary search, Greedy, Math, Sorting
- Solved
- No attempts yet
Problem
There is an array of real numbers. The -th number is . Initially, all are distinct.
In each operation, you may choose any number of the and set the value of each chosen to the average of the chosen numbers. The chosen numbers do not need to be consecutive. For example, you may choose and without choosing . You may apply the operation at most times.
Find the maximum possible value of .
Input
The first line contains three positive integers , , and . They are the length of the array, the maximum number of operations, and the required precision.
The second line contains positive integers. The -th integer is . All are distinct, and .
Output
Print the maximum possible as a real number on one line. The integer part is required. Print the decimal point only if there is a decimal part. You may print at most digits after the decimal point, and at least digits is recommended. The reference answer differs from the true answer by at most .
Your answer is correct if its absolute difference from the reference answer is less than . If the difference is at least but less than , you receive 40% of the points for that test case.
Constraints
For all test cases, , , and .
Hints
To guarantee precision, keep more than digits after the decimal point in arithmetic operations when possible. The reference solution for each subtask keeps the absolute error below when each operation keeps at most digits after the decimal point.
A high-precision library, library.zip, is provided. Using it is optional.
The Decimal library supports addition, subtraction, multiplication, division, comparison, and conversion to and from double, integers, and strings. For multiplication and division, one operand must be an integer. You cannot multiply or divide two Decimal values.
The library defines the constant , the maximum absolute error of each operation, which is . In the C++ version, line 9 of drink_sample.cpp sets it with const int PREC = 2100;. In the C version, line 9 of drink_sample.c sets it with #define PREC 2100. In the Pascal version, lines 8 and 14 of drink_sample.pas both contain 2100. If you change , change every occurrence to the same value. Each operation takes time. Each Decimal instance takes at most bytes.
When calling Decimal functions, follow these conditions:
- Every intermediate
Decimalvalue has an absolute value of at most . intandlongintarguments have absolute values of at most .long longandint64arguments have absolute values of at most .- A
doubleargument is a valid real number with absolute value at most . - A
stringargument is a valid real number. A negative number starts with a minus sign, and a non-negative number has no sign. It has an integer part, then a decimal point, then a decimal part. The decimal point and decimal part may both be omitted. Its absolute value is at most . - Do not divide by zero.
- When converting a
Decimalto a string, the number of digits after the decimal point must be greater than zero. In C, allocate enough space for the string returned byto_string_d(Decimal, char*, int).
The programs drink_sample.cpp/c/pas contain only the library. You may work on them directly, but you do not have to. The programs decimal_test.cpp/c/pas show how to use the Decimal library and each of its functions.