Overtime
InterviewTime limit2sMemory limit512 MB
Given timestamped enter and leave records, count overtime as unmatched leaves plus unmatched enters per name after pairing.
- Level
Medium4 of 10
- Topics
- Hash map, Stack, String, Implementation
- Solved
- No attempts yet
Problem
Yeongseon Company is a company where overtime is very common. Fortunately it does pay overtime, but its boss, nein, is a very stingy boss and tries to pay as little overtime as possible.
Yeongseon Company decides who worked overtime as follows. You are given the entry and exit records from very early in the morning until closing time. If there is an exit record without an entry record, it is recorded as overtime worked at the company. If someone entered the company and did not leave by closing time, that is also recorded as overtime. Depending on the records, both criteria can hold at once, and then it counts as two overtimes. However, if someone stayed at the company the whole time and never left or entered, so there is no record, it does not count as overtime.
The records have a serious flaw: they cannot tell apart people with the same name. Records with the same name are treated as one person, and overtime counts more than once only when it is clearly visible, for example when two people with that name both remain in the company, or both have exit records without entry records.
In other words, for each name, read its records in time order and pair each exit record with an earlier entry record of the same name that has not been paired yet. Each exit record left without a pair and each entry record still without a pair at the end counts as one overtime.
You are given today's entry and exit records of Yeongseon Company. Using them, print the total number of overtimes over all employees.
Input
The first line contains the number of records . ()
Each of the next lines contains a name and a direction , separated by a space, in time order. is + for entering and - for leaving. A name consists of lowercase English letters only and is at most 30 characters long.
Output
Print the total number of overtimes over all employees, based on the records.