更好的阅读体验
B. Glass Half Spilled
题目描述
There are n n n glasses on the table numbered 1 , … , n 1, \ldots, n 1,…,n. The glass i i i can hold up to a i a_i ai units of water, and currently contains b i b_i bi units of water.
You would like to choose k k 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 i i currently contains c i c_i ci units of water, and a glass j j j contains c j c_j cj units of water. Suppose you try to transfer x x x units from glass i i i to glass j j j (naturally, x x x can not exceed c i c_i ci). Then, x / 2 x / 2 x/2 units is spilled on the floor. After the transfer is done, the glass i i i will contain c i − x c_i - x ci−x units, and the glass j j j will contain min ( a j , c j + x / 2 ) \min(a_j, c_j + x / 2) min(aj,cj+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 i i to which glass j j j to pour, and also the amount x x