欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1526C2.Potions (Hard Version)
Potions (Hard Version)
CF1526C2 · Potions (Hard Version)
- 难度:1600
- 标签:data structures、greedy
- 链接:https://codeforces.com/problemset/problem/1526/C2
- 时间限制:1 second 内存限制:256 megabytes
- 出现位置:Day04-反悔贪心-优先队列-排序贡献
英文原题面
Statement
This is the hard version of the problem. The only difference is that in this version . You can make hacks only if both versions of the problem are solved. There are potions in a line, with potion on the far left and potion on the far right. Each potion increases your health by when drunk. can be negative, meaning that the potion decreases your health. You start with health, and you will walk from left to right, from the first potion to the last one. At each potion, you may choose to drink it or ignore it. You must ensure that your health is always non-negative. What is the largest number of potions you can drink?
Input
The first line contains a single integer () — the number of potions. The next line contains integers , , ... , () which represent the change in health after drinking that potion.
Output
Output a single integer, the maximum number of potions you can drink without your health becoming negative.
样例
样例 1
输入:
6
4 -4 1 -3 1 -3
输出:
5
样例解释(英文原文)
For the sample, you can drink potions by taking potions , , , and . It is not possible to drink all potions because your health will go negative at some point
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |