A single service counter opens at time 0 and serves customers strictly in the order they arrive (first-come-first-served), one at a time. You are given n customers' arrival times, given in non-decreasing order (since they form a single physical line), and a fixed service duration s: every customer takes exactly s minutes once their service begins.
Service of the next customer in line begins at max(arrival time, counter free time). A customer's wait time is (service start time - arrival time).
Count how many customers wait STRICTLY MORE than w minutes before being served.
Line 1: three integers n, s, w.
Line 2: n space-separated non-decreasing integers, the arrival times.
A single integer: the number of customers whose wait time is strictly greater than w.
Example 1
Input
3 5 3 0 1 2
Expected
2
Explanation
The first customer is served immediately (no wait). The second and third must wait until the counter frees at times 5 and 10, waiting 4 and 8 minutes respectively - both exceed the 3-minute threshold, so the count is 2.
Example 2
Input
2 2 5 0 10
Expected
0
Explanation
Both customers arrive when the counter is already free (the second arrives long after the first finished), so neither one waits at all.
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 →