IBMOA #68
Service Timeout Detection
估计简单可在线判题
Each heartbeat record contains a timestamp and the ID of the service it belongs to. For each service ID, sort its heartbeats by timestamp; if the interval between any two adjacent heartbeats is strictly greater than threshold, the service is considered to have timed out at least once. A service with only one heartbeat never times out. Note that the heartbeats in the input are not sorted by timestamp.
Find all service IDs that timed out at least once and output them in ascending lexicographic order.
输入格式
The first line contains two integers n and threshold. Each of the next n lines contains an integer timestamp and a string serviceId. 1≤n≤200000, 1≤timestamp≤10^9, 0≤threshold≤10^9, and serviceId has length 1..10 and contains only lowercase letters and digits.
输出格式
Output the number k of timed-out services on the first line; then output k lines, one service ID each, in ascending lexicographic order.
样例 1
输入:
5 30
10 svc1
20 svc1
80 svc1
10 svc2
65 svc2
输出:
2
svc1
svc2
样例 2
输入:
3 1
1 svc1
2 svc2
3 svc1
输出:
1
svc1
样例 3
输入:
4 5
3 b
1 a
6 b
4 a
输出:
0
样例说明
Example 1: svc1 has a gap of 60 between 20 and 80, and svc2 has a gap of 55 between 10 and 65; both exceed 30, so 2 services are output. Example 2: svc1 has a gap of 2 between 1 and 3, which exceeds 1; svc2 has only one heartbeat and does not time out, so 1 service, svc1, is output. Example 3: a has heartbeats 1 and 4, and b has heartbeats 3 and 6; both gaps are 3, which does not exceed 5, so the output is 0.