CF1526C1.Potions (Easy Version)

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easy version of the problem. The only difference is that in this version n≤2000n \leq 2000. You can make hacks only if both versions of the problem are solved.

There are nn potions in a line, with potion 11 on the far left and potion nn on the far right. Each potion increases your health by aia_i when drunk. aia_i can be negative, meaning that the potion decreases your health.

You start with 00 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?

这是该问题的简单版本。唯一的区别在于本版本中 n≤2000n \leq 2000。仅当两个版本的问题均被解决时,你才可以进行 hack。

一行中有 nn 瓶药水,其中第 11 瓶药水位于最左侧,第 nn 瓶药水位于最右侧。每瓶药水在饮用后会使你的生命值增加 aia_i。aia_i 可以为负数,表示该药水会降低你的生命值。

你初始生命值为 00,并将从左到右依次经过所有药水(即从第 11 瓶走到第 nn 瓶)。在每一瓶药水处,你可以选择饮用它或忽略它,但必须保证在任意时刻你的生命值始终非负。

你最多能喝多少瓶药水?

输入格式

The first line contains a single integer nn (1≤n≤20001 \leq n \leq 2000) — the number of potions.

The next line contains nn integers a1a_1, a2a_2, ... ,ana_n (−109≤ai≤109-10^9 \leq a_i \leq 10^9) which represent the change in health after drinking that potion.

第一行包含一个整数 nn(1≤n≤20001 \leq n \leq 2000)—— 表示药水的数量。

第二行包含 nn 个整数 a1a_1, a2a_2, ..., ana_n(−109≤ai≤109-10^9 \leq a_i \leq 10^9),表示饮用对应药水后生命值的变化量。

输出格式

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 55 potions by taking potions 11, 33, 44, 55 and 66. It is not possible to drink all 66 potions because your health will go negative at some point

对于样例,你可以通过服用第 11、33、44、55 和 66 瓶药水来喝下 55 瓶药水。无法喝下全部 66 瓶药水,因为在某个时刻你的生命值会变为负数。

输入解题思路,AI测评打分。不知道怎么写?

首页