欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1800C1.Powering the Hero (easy version)
Powering the Hero (easy version)
This is an easy version of the problem. It differs from the hard one only by constraints on and .
There is a deck of cards, each of which is characterized by its power. There are two types of cards:
- a hero card, the power of such a card is always equal to ;
- a bonus card, the power of such a card is always positive.
You can do the following with the deck:
- take a card from the top of the deck;
- if this card is a bonus card, you can put it on top of your bonus deck or discard;
- if this card is a hero card, then the power of the top card from your bonus deck is added to his power (if it is not empty), after that the hero is added to your army, and the used bonus discards.
Your task is to use such actions to gather an army with the maximum possible total power.
Input
The first line of input data contains single integer () — the number of test cases in the test.
The first line of each test case contains one integer () — the number of cards in the deck.
The second line of each test case contains integers () — card powers in top-down order.
It is guaranteed that the sum of over all test cases does not exceed .
Output
Output numbers, each of which is the answer to the corresponding test case — the maximum possible total power of the army that can be achieved.
Note
In the first sample, you can take bonuses and . Both hero cards will receive power. If you take all the bonuses, one of them will remain unused.
In the second sample, the hero's card on top of the deck cannot be powered up, and the rest can be powered up with and bonuses and get total power.
In the fourth sample, you can take bonuses , , , and skip the bonus , then the hero will be enhanced with a bonus by , and the hero with a bonus by . .
Samples
5
5
3 3 3 0 0
6
0 3 3 0 0 3
7
1 2 3 0 4 5 0
7
1 2 5 0 4 3 0
5
3 1 0 0 4
6
6
8
9
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |