#P7137. [THUPC 2021 初赛] 切切糕

[THUPC 2021 初赛] 切切糕

Description

Kiana likes desserts. One day, she bought NN cutcakes from a store and shared them with Tinytree. The size of the ii-th cutcake is represented by a number AiA_i.

Since each cutcake has a different flavor, Kiana and Tinytree decide to cut each cutcake into two parts, and each person chooses one part to taste. However, cutting cutcakes is a difficult problem that has existed since ancient times. After discussion, Kiana will do the cutting, and Tinytree has MM chances of “priority choosing rights”, which allow her to have priority to choose after a cut. Specifically, they operate as follows:

Step 1: Kiana chooses one uncut cutcake in any way she wants, and cuts it into two parts. The size of each part can be any positive real number, or can be 0\mathbf{0}, and the sum of the two parts equals the size before cutting.

Step 2: After observing the sizes of the two parts cut by Kiana, if Tinytree still has remaining “priority choosing rights”, she may decide whether to spend 11 “priority choosing right” to make a priority choice.

Step 3: If Tinytree chooses to use a “priority choosing right”, she can choose either part, and the other part goes to Kiana. If Tinytree chooses not to use it, or she has already used up all MM “priority choosing rights”, then Kiana chooses either part, and the other part goes to Tinytree. Then they return to Step 1 until all cutcakes have been cut.

Assume both Kiana and Tinytree are smart enough: whenever it is their turn to act, they always try to maximize the final total size of cutcakes they obtain. Also, before cutting the first cutcake, the sizes of all NN cutcakes are known to both of them. Tinytree does not have to use up all “priority choosing rights”. Now Kiana wants to know the total size of cutcakes she can obtain. Since Kiana cannot compute it herself, she asks you to help.

Input Format

The first line contains two positive integers NN and MM (1MN25001 \le M \le N \le 2500), representing the total number of cutcakes and the initial number of Tinytree’s “priority choosing rights”, respectively.
The second line contains NN positive integers. The ii-th number AiA_i (1Ai500001 \le A_i \le 50000) represents the size of the ii-th cutcake.

Output Format

Output one line containing a real number, representing the final total size of cutcakes that Kiana can obtain. All outputs should be accurate to six digits after the decimal point.

4 3
4 3 2 1

5.250000

Hint

Sample Explanation #1.

In this sample, there are 44 cutcakes with sizes 4,3,2,14,3,2,1. Tinytree has three “priority choosing rights”. They can distribute the cutcakes in the following order and manner:

First cutcake: Kiana chooses the cutcake of size 33 and cuts it into two parts of sizes 1.251.25 and 1.751.75. Tinytree uses one “priority choosing right” and takes the part of size 1.751.75. Kiana has obtained a total size of 1.251.25 so far.

Second cutcake: Kiana chooses the cutcake of size 11 and cuts it into two parts of sizes 00 and 11. Tinytree does not use a “priority choosing right”, and Kiana takes the whole cutcake. Kiana has obtained a total size of 2.252.25 so far.

Third cutcake: Kiana chooses the cutcake of size 22 and cuts it into two parts of sizes 11 and 11. Tinytree uses one “priority choosing right” and takes the part of size 11. Kiana has obtained a total size of 3.253.25 so far.

Fourth cutcake: Kiana chooses the cutcake of size 44 and cuts it into two parts of sizes 22 and 22. Tinytree uses one “priority choosing right” and takes the part of size 22. Kiana has obtained a total size of 5.255.25 so far.

Therefore, the output for this sample is 5.2500005.250000. It can also be proven that under this plan, if either person changes their strategy, their final total size of cutcakes cannot become larger.

Source of the Problem.

From the preliminary round of the 2021 Tsinghua University Student Programming Contest and Collegiate Invitational Contest (THUPC2021).

Resources such as editorials can be found at https://github.com/THUSAAC/THUPC2021-pre.

Translated by ChatGPT 5