Skip to content
TheChatArchiveThe Chat Archive
DeepSeekDeepseek v3.2· deepseekHugging Face Frontier Reasoning Traces

The police department of your city has just started its journey. Initially, they don’t…

  1. User

    The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.

    Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.

    If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.

    Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. Input

    The first line of input will contain an integer n (1 ≤ n ≤ 105), the number of events. The next line will contain n space-separated integers.

    If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.

    Output

    Print a single integer, the number of crimes which will go untreated.

    Examples

    Input

    3 -1 -1 1

    Output

    2

    Input

    8 1 -1 1 -1 -1 1 1 1

    Output

    1

    Input

    11 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1

    Output

    8

    Note

    Lets consider the second example:

    1. Firstly one person is hired.
    2. Then crime appears, the last hired person will investigate this crime.
    3. One more person is hired.
    4. One more crime appears, the last hired person will investigate this crime.
    5. Crime appears. There is no free policeman at the time, so this crime will go untreated.
    6. One more person is hired.
    7. One more person is hired.
    8. One more person is hired.

    The answer is one, as one crime (on step 5) will go untreated.

  2. DeepSeek Assistant

    We need to parse the problem: We have n events, each event is either a crime (-1) or a positive integer representing the number of officers hired at that time. Initially there are 0 officers. Each police officer can investigate exactly one crime during their lifetime; after they investigate a crime, they are no longer available. Crime occurrences: If there is at least one free officer at the time of the crime, one officer will be assigned to investigate that crime, reducing the number of free officers by 1. If there are no free officers, the crime goes untreated and we count it. Hiring events: They add that many free officers to the pool. However, note that the police department may have hired officers earlier, some might be busy investigating crimes, but since each officer can only do one crime ever, after they've investigated they are gone? Actually "one member of the police force can investigate only one crime during his/her lifetime." So after an officer investigates a crime, they are no longer available (maybe retired, or maybe they die? but effectively they are removed). So the model: we have a pool of available officers. Initially 0. For each event: if positive integer x: add x to pool. If -1: if pool > 0, then pool -= 1 (one officer handles the crime and is removed from pool). If pool == 0, then untreated crime count increments.

    That's straightforward.

    But check constraints: n up to 1e5, each positive integer is at most 10. So straightforward simulation O(n) works.

    Examples confirm.

    Edge cases: consecutive hires and crimes. Implementation: read n, read list a. Set free = 0, untreated = 0. For each v in a: if v > 0: free += v else: if free > 0: free -= 1 else: untreated += 1.

    Output untreated.

    Check example2: events: 1, -1, 1, -1, -1, 1, 1, 1. Simulate: free=0 untreated=0. v=1 -> free=1. v=-1 -> free>0 -> free=0. v=1 -> free=1. v=-1 -> free>0 -> free=0. v=-1 -> free==0 -> untreated=1. v=1 -> free=1. v=1 -> free=2. v=1 -> free=3. So untreated=1.

    Example3: events: -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1. Simulate: first -1: free=0 -> untreated=1; second -1: untreated=2; third 2: free=2; then successive 8 times -1: first -1: free=2 -> free=1; second -1: free=1 -> free=0; third -1: free=0 -> untreated=3; fourth -1: untreated=4; fifth -1: untreated=5; sixth -1: untreated=6; seventh -1: untreated=7; eighth -1: untreated=8. So untreated=8. matches.

    So solution is trivial.

    But let's ensure about "one member of the police force can investigate only one crime during his/her lifetime." Means when they are assigned to a crime, they are consumed, so indeed free--. There's no concept of them being busy and then returning to pool later. So yes.

    Thus we can answer.

    But perhaps there is nuance: "If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated." This wording "isn't busy with crime" suggests that if an officer is busy investigating a crime, they are not free. But we only have one-time use: after investigating, they are gone. So it's same.

    Anyway, solution as above.

    Complexity O(n).

    Let's produce final answer.

    We'll need to write code in C++? The problem statement doesn't specify language; but typical solution can be in C++ or Python. We'll write in Python for readability.

    Pseudo-code:

    def main(): import sys data = sys.stdin.read().split() n = int(data[0]) events = list(map(int, data[1:])) free = 0 untreated = 0 for e in events: if e == -1: if free > 0: free -= 1 else: untreated += 1 else: free += e print(untreated)

    Edge: Input may have extra spaces; we handle.

    Thus final answer.

    We'll produce final message with explanation and code. ```python

    import sys

    def main() -> None: data = sys.stdin.read().split() if not data: return n = int(data[0]) events = list(map(int, data[1:1 + n])) free = 0 untreated = 0 for e in events: if e == -1: # crime occurs if free > 0: free -= 1 # one officer handles it and leaves else: untreated += 1 else: # hiring of e officers free += e print(untreated)

    if name == "main": main()