PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000077. Những chiếc ly đổ mất một nửa (Glass Half Spilled)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những chiếc ly đổ mất một nửa (Glass Half Spilled)

Glass Half Spilled

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn glasses numbered 1,2,…,n1,2,\ldots,n. Glass ii has capacity aia_i and currently holds bib_i units of water, with 0≤bi≤ai0\le b_i\le a_i. For each k=1,2,…,nk=1,2,\ldots,n, choose exactly kk glasses and maximize the total amount of water remaining in those chosen glasses.

You may transfer water between glasses any number of times. In one transfer of x>0x>0 units from glass ii to glass jj, exactly half the transferred amount is spilled. The source loses xx units, and the destination receives only x/2x/2 units, subject to its capacity. If the initial amounts are ci,cjc_i,c_j, then the resulting amounts are

ci′=ci−x,cj′=min⁡(aj,cj+x/2).c_i'=c_i-x,\qquad c_j'=\min(a_j,c_j+x/2).

The transferred amount xx may be any positive real number not exceeding the water in the source glass. For every kk, you may independently choose the kk glasses and any sequence of transfers. Print the optimal retained total for each value of kk; the glass indices and transfer instructions are not required. Each answer is accepted with an absolute or relative error of at most 10−910^{-9}.

Input

The first line contains nn. Each of the next nn lines contains integers ai,bia_i,b_i, the capacity and initial water amount of glass ii.

Output

Print exactly nn real numbers on one line: the optimal amounts for k=1,2,…,nk=1,2,\ldots,n, separated by spaces. Absolute or relative error up to 10−910^{-9} is permitted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤101\le n\le10; 1≤ai≤201\le a_i\le20; 0≤bi≤ai0\le b_i\le a_i; tolerance 10−910^{-9}.

  • Subtask 2 (30 points): 1≤n≤401\le n\le40; 1≤ai≤601\le a_i\le60; 0≤bi≤ai0\le b_i\le a_i; tolerance 10−910^{-9}.

  • Subtask 3 (50 points): 1≤n≤1001\le n\le100; 1≤ai≤1001\le a_i\le100; 0≤bi≤ai0\le b_i\le a_i; tolerance 10−910^{-9}.

Examples

Example 1

Input

3
6 5
6 5
10 2

Output

7.0000000000 11.0000000000 12.0000000000

Explanation

There are 1212 units initially. For k=1k=1, keep the third glass and pour 55 units from each other glass, gaining 2.5+2.52.5+2.5 for a retained total of 77. For k=2k=2, retain the first two glasses and gain 11 from the third, yielding 1111. For k=3k=3, keep all water without transferring, yielding 1212.

Example 2

Input

2
6 1
6 5

Output

5.5000000000 6.0000000000

Explanation

For k=1k=1, retain the second glass with 55 units and transfer 11 from the first to gain 0.50.5, totaling 5.55.5. For k=2k=2, keep all 66 units without transfers.