A14347 | Potions (Easy Version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$ . You can make hacks only if both versions of the problem are solved.
There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when drunk. $a_i$ can be negative, meaning that potion will decrease will health.
You start with $0$ health and you will walk from left to right, from 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?
There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when drunk. $a_i$ can be negative, meaning that potion will decrease will health.
You start with $0$ health and you will walk from left to right, from 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?
输入格式
The first line contains a single integer $n$ ( $1 \leq n \leq 2000$ ) — the number of potions.
The next line contains $n$ integers $a_1$ , $a_2$ , ... , $a_n$ ( $-10^9 \leq a_i \leq 10^9$ ) which represent the change in health after drinking that potion.
The next line contains $n$ integers $a_1$ , $a_2$ , ... , $a_n$ ( $-10^9 \leq a_i \leq 10^9$ ) which represent the change in health after drinking that potion.
输出格式
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
输出 #1
5
For the sample, you can drink $5$ potions by taking potions $1$ , $3$ , $4$ , $5$ and $6$ . It is not possible to drink all $6$ potions because your health will go negative at some point
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted