Serves Me Right
Time limit2sMemory limit256 MB
Replay logins, logouts, restarts, and session timeouts to count distinct users and the highest number logged in at once.
- Level
Medium4 of 10
- Topics
- Simulation, Hash map, Intervals
- Solved
- No attempts yet
Problem
You look after a web server. Your company pays for concurrent licenses, so users can be logged in at the same time. The company is cutting costs everywhere, and your supervisor wants to know whether all licenses are really needed.
The server logs three kinds of events.
- the time a user connects and a session starts
- the time a user disconnects and the session is removed
- the time the server restarts
Users do not always log out; some just close the browser. Each session therefore has a timeout of minutes. A session that starts at time ends at time , and that user is already disconnected at . The automatic disconnect is not logged.
If a user whose session is still open records another LOG_IN, the session starts again from that moment and ends minutes later.
When the server restarts, every user is disconnected at that moment and every session is removed.
You are given one day of server log and the session timeout. Report how many different users appear in the log, and the largest number of users logged in at the same time.
Input
The first line has one integer , the number of logs to process ().
Each log starts with a line holding the number of entries and the session timeout in minutes, separated by a space (). Then follow lines, one entry each, in one of two forms:
TIME SERVER RESTART
TIME USER USER_NAME USER_ACTION
TIME is HH:MM on a 24 hour clock. USER_NAME is a string of 1 to 16 lowercase English letters, and the same name always means the same user. USER_ACTION is either LOG_IN or LOG_OUT. Entries come in increasing order of time, and all times inside one log are different. The log has no inconsistency: LOG_OUT appears only for a user whose session is open at that time. Not all users have to appear in the log.
Output
For each log, print the number of different users that appear in the log and the largest number of users logged in at the same time, separated by one space, on a single line.