欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1458B.Glass Half Spilled
Glass Half Spilled
There are glasses on the table numbered . The glass can hold up to units of water, and currently contains units of water.
You would like to choose 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 currently contains units of water, and a glass contains units of water. Suppose you try to transfer units from glass to glass (naturally, can not exceed ). Then, units is spilled on the floor. After the transfer is done, the glass will contain units, and the glass will contain 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 to which glass to pour, and also the amount transferred can be any positive real number.
For each , determine the largest possible total amount of water that can be collected in arbitrarily chosen glasses after transferring water between glasses zero or more times.
Input
The first line contains a single integer () — the number of glasses.
The following lines describe the glasses. The -th of these lines contains two integers and (, ) — capacity, and water amount currently contained for the glass , respectively.
Output
Print real numbers — the largest amount of water that can be collected in glasses respectively. Your answer will be accepted if each number is within absolute or relative tolerance of the precise answer.
Note
In the sample case, you can act as follows:
- for , transfer water from the first two glasses to the third one, spilling units and securing units;
- for , transfer water from the third glass to any of the first two, spilling unit and securing units;
- for , do nothing. All units are secured.
Samples
3
6 5
6 5
10 2
7.0000000000 11.0000000000 12.0000000000
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |