Police Recruits
Practice this coding question on Coding Gurukul.
Problem statement
A campus safety desk receives a chronological event stream. A positive entry adds newly available officers to the desk, while -1 reports an incident requiring one officer. Once assigned to an incident, an officer is no longer available for later events in this simplified model. The desk wants to count incidents that could not be handled immediately because nobody was available. Your task Start with zero available officers. For each positive event, add that many officers. For an event of -1, assign one officer if possible; otherwise increase the untreated-incident count. Process the stream in order and report the number of untreated incidents. Important details Future recruits cannot retroactively handle earlier incidents. Availability never becomes negative. Several consecutive recruit events accumulate their officers, while several incidents consume that pool one at a time. Worked example For events -1, 2, -1, -1, -1, the first incident is untreated, the next two consume the recruits, and the final incident is untreated. Print 2.
Input format
First line: n. Second line: n events.
Output format
Print the number of untreated incidents.
Constraints
1 <= n <= 100000; each event is -1 or an integer from 1 to 10.
Sample input
5 -1 2 -1 -1 -1
Sample output
2
Sign in to run or submit a solution in C++, Java or Python.