CF1458B Glass Half Spilled
Description
There are $ n $ glasses on the table numbered $ 1, \ldots, n $ . The glass $ i $ can hold up to $ a_i $ units of water, and currently contains $ b_i $ units of water.
You would like to choose $ k $ glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, because of the glasses' awkward shape (and totally unrelated to your natural clumsiness), each time you try to transfer any amount of water, half of the amount is spilled on the floor.
Formally, suppose a glass $ i $ currently contains $ c_i $ units of water, and a glass $ j $ contains $ c_j $ units of water. Suppose you try to transfer $ x $ units from glass $ i $ to glass $ j $ (naturally, $ x $ can not exceed $ c_i $ ). Then, $ x / 2 $ units is spilled on the floor. After the transfer is done, the glass $ i $ will contain $ c_i - x $ units, and the glass $ j $ will contain $ \min(a_j, c_j + x / 2) $ units (excess water that doesn't fit in the glass is also spilled).
Each time you transfer water, you can arbitrarlly choose from which glass $ i $ to which glass $ j $ to pour, and also the amount $ x $ transferred can be any positive real number.
For each $ k = 1, \ldots, n $ , determine the largest possible total amount of water that can be collected in arbitrarily chosen $ k $ glasses after transferring water between glasses zero or more times.
Input Format
N/A
Output Format
N/A
Explanation/Hint
In the sample case, you can act as follows:
2. for $ k = 1 $ , transfer water from the first two glasses to the third one, spilling $ (5 + 5) / 2 = 5 $ units and securing $ 2 + (5 + 5) / 2 = 7 $ units;
3. for $ k = 2 $ , transfer water from the third glass to any of the first two, spilling $ 2 / 2 = 1 $ unit and securing $ 5 + 5 + 2 / 2 = 11 $ units;
4. for $ k = 3 $ , do nothing. All $ 5 + 5 + 2 = 12 $ units are secured.