#QHD0000077. Những chiếc ly đổ mất một nửa (Glass Half Spilled)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 glasses numbered . Glass has capacity and currently holds units of water, with . For each , choose exactly 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 units from glass to glass , exactly half the transferred amount is spilled. The source loses units, and the destination receives only units, subject to its capacity. If the initial amounts are , then the resulting amounts are
The transferred amount may be any positive real number not exceeding the water in the source glass. For every , you may independently choose the glasses and any sequence of transfers. Print the optimal retained total for each value of ; the glass indices and transfer instructions are not required. Each answer is accepted with an absolute or relative error of at most .
Input
The first line contains . Each of the next lines contains integers , the capacity and initial water amount of glass .
Output
Print exactly real numbers on one line: the optimal amounts for , separated by spaces. Absolute or relative error up to is permitted.
Subtasks
-
Subtask 1 (20 points): ; ; ; tolerance .
-
Subtask 2 (30 points): ; ; ; tolerance .
-
Subtask 3 (50 points): ; ; ; tolerance .
Examples
Example 1
Input
3
6 5
6 5
10 2
Output
7.0000000000 11.0000000000 12.0000000000
Explanation
There are units initially. For , keep the third glass and pour units from each other glass, gaining for a retained total of . For , retain the first two glasses and gain from the third, yielding . For , keep all water without transferring, yielding .
Example 2
Input
2
6 1
6 5
Output
5.5000000000 6.0000000000
Explanation
For , retain the second glass with units and transfer from the first to gain , totaling . For , keep all units without transfers.