A helpdesk's ticketing system logs every time an agent logs in and later logs out; an agent may log in and out several times across a single day. Each log line records an agent's id, the day, and the login and logout minute of one session on that day. Build a ledger showing, for every agent and day that appears in the log, the total number of minutes that agent was logged in that day (the sum of logout - login over all of that agent's sessions on that day).
Line 1: an integer n, the number of session records.
Each of the next n lines contains four integers empId day inTime outTime — one login session, where inTime < outTime.
For every distinct (empId, day) pair that appears in the log, print one line empId day totalMinutes, where totalMinutes is the sum of outTime - inTime over all sessions with that exact empId and day. Print the lines ordered by empId ascending, breaking ties by day ascending.
Example 1
Input
4 1 1 480 540 1 1 600 650 2 1 400 430 1 2 500 560
Expected
1 1 110 1 2 60 2 1 30
Explanation
Agent 1 has two sessions on day 1 (60 + 50 = 110 minutes) and one session on day 2 (60 minutes). Agent 2 has one session on day 1 (30 minutes). Sorted by agent then day: (1,1,110), (1,2,60), (2,1,30).
Example 2
Input
1 5 3 100 160
Expected
5 3 60
Explanation
There is a single session for agent 5 on day 3 lasting 160 - 100 = 60 minutes, giving one output line.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →