Hanging Out on the Terrace
InterviewTime limit1sMemory limit512 MB
Track how many people are on a terrace with a limit L and count how many enter groups are turned away because they would exceed it.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
The HiQ office in Stockholm has a pretty nice rooftop terrace, often used for company parties and events such as programming competitions.
Unfortunately, fire safety rules limit the number of people who can be on the terrace at any one time: at most people. During a party, people come and go to the terrace, but keeping track of how many people are currently on the terrace is a nuisance. On top of that, people often enter the terrace in groups. If a group wants to enter the terrace but their addition would exceed the fire safety limit, the group goes inside to play ping pong instead.
Your task is to write a program that, given the sizes of the groups that attempted to enter the terrace during a party and when people left the terrace, determines how many times a group was denied entry to the terrace.
Input
The first line of input contains the fire safety limit and the number of events .
The next lines contain the events. Each event begins with one of the words "enter" or "leave", depending on whether the event describes a group attempting to enter the terrace or a set of people leaving it.
This is followed by an integer , the number of people entering or leaving at this time.
The number of people who leave the terrace will never exceed the number of people currently on the terrace.
Output
Output the number of groups that were not allowed to enter the terrace during the party.