欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2128A.Recycling Center
Recycling Center
In the recycling center, there are trash bags, the -th bag has a weight of . At each second, two actions will happen successively:
- First, you must choose a trash bag and destroy it. It will cost coin if the weight of the trash bag is strictly greater than , and it will cost coins otherwise.
- Then, the weight of each remaining trash bag will get multiplied by two.
What is the minimum number of coins you have to spend to get rid of all trash bags?
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and (, .
The second line of each test case contains integers () — the weight of each trash bag.
Output
For each test case, you must output a single integer — the minimum number of coins you have to spend to destroy all trash bags.
Note
In the following explanation:
- Numbers in blue represent trash bags that have been destroyed for free,
- Numbers in red represent trash bags that have been destroyed for coin,
- Numbers in black represent trash bags that have not been destroyed yet.
In the first test case, one solution is:
- , is destroyed for free because .
- , is destroyed for free because .
- $[\color{blue}{10}, \color{blue}{8}, 120, 8, \color{red}{32}]$, is destroyed for coin because .
- $[\color{blue}{10}, \color{blue}{8}, 240, \color{blue}{8}, \color{red}{32}]$, is destroyed for free because .
- $[\color{blue}{10}, \color{blue}{8}, \color{red}{240}, \color{blue}{8}, \color{red}{32}]$, is destroyed for coin because .
In total, you paid coins, and we can prove it is optimal.
In the second test case, one solution is:
- $[1\,000\,000\,000, 1\,000\,000\,000, 1\,000\,000\,000]$
- $[\color{red}{1\,000\,000\,000}, 2\,000\,000\,000, 2\,000\,000\,000]$, is destroyed for coin because .
- $[\color{red}{1\,000\,000\,000}, \color{red}{2\,000\,000\,000}, 4\,000\,000\,000]$, is destroyed for coin because .
- $[\color{red}{1\,000\,000\,000}, \color{red}{2\,000\,000\,000}, \color{red}{4\,000\,000\,000}]$, is destroyed for coin because .
Samples
4
5 10
10 4 15 1 8
3 42
1000000000 1000000000 1000000000
10 30
29 25 2 12 15 42 14 6 16 9
10 1000000
1 1 1 1 1 1 1 1 1 864026633
2
3
6
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |