IBMOA #8
User Sessions
Estimated EasyJudge-ready
Topics (AI-labelled)HashingIn-place Arrays
Sort each user's events by time; consecutive events whose time difference does not exceed t belong to the same session, otherwise a new session starts. Find the total number of sessions across all users. Different users are never merged.
Input
The first line contains n t, followed by n lines of user ID and time. On this site 1≤n≤200000, 0≤time,t≤10^12; an ID is 1 to 32 ASCII letters or digits; events may be out of order or repeated.
Output
Output one integer, the answer.
Example 1
Input:
5 10
a 1
b 2
a 5
a 100
b 3
Output:
3
Example 2
Input:
3 10
a 0
a 10
a 20
Output:
1
Example 3
Input:
3 0
a 1
a 1
b 1
Output:
2
Example notes
The examples give 3, 1 and 2 respectively; a gap exactly equal to the timeout still stays in the same session.
Editorial
Loading solution…