CF BUDDY
← Problems·

1458B · Glass Half Spilled

2000 · dp

Problem: There are nn glasses on the table numbered 1,,n1, \ldots, n. The glass ii can hold up to aia_i units of water, and currently contains bib_i units of water.

You would like to choose kk 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 ii currently contains cic_i units of water, and a glass jj contains cjc_j units of water. Suppose you try to transfer xx units from glass ii to glass jj (naturally, xx can not exceed cic_i). Then, x/2x / 2 units is spilled on the floor. After the transfer is done, the glass ii will contain cixc_i - x units, and the glass jj will contain min(aj,cj+x/2)\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 ii to which glass jj to pour, and also the amount xx transferred can be any positive real number.

For each k=1,,nk = 1, \ldots, n, determine the largest possible total amount of water that can be collected in arbitrarily chosen kk glasses after transferring water between glasses zero or more times.

Input Format: The first line contains a single integer nn (1n1001 \leq n \leq 100) — the number of glasses.

The following nn lines describe the glasses. The ii-th of these lines contains two integers aia_i and bib_i (0biai1000 \leq b_i \leq a_i \leq 100, ai>0a_i > 0) — capacity, and water amount currently contained for the glass ii, respectively.

Output Format: Print nn real numbers — the largest amount of water that can be collected in 1,,n1, \ldots, n glasses respectively. Your answer will be accepted if each number is within 10910^{-9} absolute or relative tolerance of the precise answer.

Note: In the sample case, you can act as follows:

  • for k=1k = 1, transfer water from the first two glasses to the third one, spilling (5+5)/2=5(5 + 5) / 2 = 5 units and securing 2+(5+5)/2=72 + (5 + 5) / 2 = 7 units;
  • for k=2k = 2, transfer water from the third glass to any of the first two, spilling 2/2=12 / 2 = 1 unit and securing 5+5+2/2=115 + 5 + 2 / 2 = 11 units;
  • for k=3k = 3, do nothing. All 5+5+2=125 + 5 + 2 = 12 units are secured.

Sample Cases

Case 1

Input

3
6 5
6 5
10 2

Output

7.0000000000 11.0000000000 12.0000000000

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback