PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000096. Uống nhiều thuốc nhất – bản khó (Potions (Hard Version))
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Uống nhiều thuốc nhất – bản khó (Potions (Hard Version))
Potions (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are potions in order; taking potion changes health by , which may be negative. Starting at zero health, you may take or skip each potion while moving left to right. Health must remain nonnegative after every taken potion. Maximize the number taken.
Input
Line 1 contains . Line 2 contains integers .
Output
Print the maximum possible number of potions taken.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
6
4 -4 1 -3 1 -3
Output
5
Explanation
Choose potions , obtaining health levels . Taking all six would give negative total health, so five is optimal.