Codey and Speeches
https://www.hackerrank.com/contests/codenection-2024-final-round-closed-category/challenges/cn24-20
Question
Codey is feeling extra motivated today (because it is the CodeNection Final day!) and wants to give motivational speeches! Codey has found n of its friends, lined up from left to right. Codey plans to deliver speeches starting from the leftmost friend and moving to the rightmost friend. For each friend, Codey can choose whether to deliver a speech or skip them.
Giving a speech to friend i will result in receiving a feedback score of . The score can be negative because some friends might find Codey's speech boring!
Codey wants to give as many speeches as possible and stay motivated at the same time. This means that the total feedback score from the speeches delivered at any point must remain greater than or equal to 0.
Find the maximum number of speeches Codey can deliver while satisfying all the conditions!
Input Format
The first line contains an integer n, which represents the number of friends.
The second line contains integers, , each representing the feedback score of the i-th friend.
Constraints
Output Format
Output an integer representing the maximum number of speeches Codey can give.
Sample Inputs:
Last updated