欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1703G.Good Key, Bad Key
Good Key, Bad Key
There are chests. The -th chest contains coins. You need to open all chests in order from chest to chest .
There are two types of keys you can use to open a chest:
- a good key, which costs coins to use;
- a bad key, which does not cost any coins, but will halve all the coins in each unopened chest, including the chest it is about to open. The halving operation will round down to the nearest integer for each chest halved. In other words using a bad key to open chest will do , $a_{i+1} = \lfloor\frac{a_{i+1}}{2}\rfloor, \dots, a_n = \lfloor \frac{a_n}{2}\rfloor$;
- any key (both good and bad) breaks after a usage, that is, it is a one-time use.
You need to use in total keys, one for each chest. Initially, you have no coins and no keys. If you want to use a good key, then you need to buy it.
During the process, you are allowed to go into debt; for example, if you have coin, you are allowed to buy a good key worth coins, and your balance will become coins.
Find the maximum number of coins you can have after opening all chests in order from chest to chest .
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains two integers and (; ) — the number of chests and the cost of a good key respectively.
The second line of each test case contains integers () — the amount of coins in each chest.
The sum of over all test cases does not exceed .
Output
For each test case output a single integer — the maximum number of coins you can obtain after opening the chests in order from chest to chest .
Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
Note
In the first test case, one possible strategy is as follows:
- Buy a good key for coins, and open chest , receiving coins. Your current balance is coins.
- Buy a good key for coins, and open chest , receiving coins. Your current balance is coins.
- Use a bad key and open chest . As a result of using a bad key, the number of coins in chest becomes , and the number of coins in chest becomes . Your current balance is .
- Use a bad key and open chest . As a result of using a bad key, the number of coins in chest becomes . Your current balance is .
At the end of the process, you have coins, which can be proven to be maximal.
Samples
5
4 5
10 10 3 1
1 2
1
3 12
10 10 29
12 51
5 74 89 45 18 69 67 67 11 96 23 59
2 57
85 60
11
0
13
60
58
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |