CF1458B.Glass Half Spilled

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ci−xc_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.

桌子上有 nn 个编号为 1,…,n1, \ldots, n 的杯子。杯子 ii 最多可盛放 aia_i 单位的水,当前盛有 bib_i 单位的水。

你希望从中选出 kk 个杯子,并尽可能多地将水汇集到这 kk 个杯子中。为此,你可以任意多次地在杯子之间倒水。然而,由于这些杯子形状怪异(且与你天生的笨拙毫无关系),每次你尝试转移任意数量的水时,所转移水量的一半都会洒到地上。

形式化地说,假设杯子 ii 当前含有 cic_i 单位的水,杯子 jj 当前含有 cjc_j 单位的水。若你尝试从杯子 ii 向杯子 jj 转移 xx 单位的水(显然,xx 不能超过 cic_i),则会有 x/2x / 2 单位的水洒到地上。转移完成后,杯子 ii 中剩余 ci−xc_i - x 单位的水,而杯子 jj 中将含有 min⁡(aj,cj+x/2)\min(a_j, c_j + x / 2) 单位的水(超出容量的多余水量也会被洒出)。

每次倒水时,你可以任意选择源杯子 ii 和目标杯子 jj,且所转移的水量 xx 可以是任意大于 0 的实数。

对每个 k=1,…,nk = 1, \ldots, n,求出:经过零次或多次杯子间倒水操作后,能在任意选定的 kk 个杯子中汇集到的最大总水量。

输入格式

The first line contains a single integer nn (1≤n≤1001 \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 (0≤bi≤ai≤1000 \leq b_i \leq a_i \leq 100, ai>0a_i \gt 0) — capacity, and water amount currently contained for the glass ii, respectively.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)——玻璃杯的数量。

接下来的 nn 行描述这些玻璃杯。其中第 ii 行包含两个整数 aia_i 和 bib_i(0≤bi≤ai≤1000 \leq b_i \leq a_i \leq 100,且 ai>0a_i \gt 0)——分别表示第 ii 个玻璃杯的容量和当前所盛水量。

输出格式

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 10−910^{-9} absolute or relative tolerance of the precise answer.

输出 nn 个实数——分别为在第 1,…,n1, \ldots, n 个杯子中所能收集到的最大水量。若每个数与精确答案的绝对误差或相对误差均在 10−910^{-9} 范围内,则你的答案将被接受。

输入输出样例

  • 输入#1

    3
    6 5
    6 5
    10 2

    输出#1

    7.0000000000 11.0000000000 12.0000000000

说明/提示

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.

在样例中,你可以按如下方式操作:

  • 当 k=1k = 1 时,将前两个杯子中的水全部倒入第三个杯子,溢出 (5+5)/2=5(5 + 5) / 2 = 5 单位,保留下 2+(5+5)/2=72 + (5 + 5) / 2 = 7 单位;
  • 当 k=2k = 2 时,将第三个杯子中的水倒入前两个杯子中的任意一个,溢出 2/2=12 / 2 = 1 单位,保留下 5+5+2/2=115 + 5 + 2 / 2 = 11 单位;
  • 当 k=3k = 3 时,不进行任何操作。全部 5+5+2=125 + 5 + 2 = 12 单位均被保留。

输入解题思路,AI测评打分。不知道怎么写?

首页