Sliding Log Rate Limiter
An API gateway protects a backend with a sliding log rate limiter. It is configured with a limit k and a window length w milliseconds, and it keeps a log of the timestamps of the requests it has accepted.
Requests arrive one by one with integer millisecond timestamps that never decrease (several requests may share a timestamp). When a request arrives at time t, the gateway counts the accepted requests whose timestamps s satisfy t − w < s ≤ t:
- if fewer than
kaccepted requests are in that window, the request is accepted andtis added to the log; - otherwise the request is rejected. Rejected requests are not logged and never count against later requests.
Requests are processed in input order, so a request accepted at time t counts for later requests that share the same timestamp t.
Report the decision for every request.
Input
The first line contains three integers n, k and w (1 ≤ n ≤ 10^6, 1 ≤ k ≤ 10^6, 1 ≤ w ≤ 10^9): the number of requests, the limit and the window length in milliseconds.
The second line contains n integers t_1, t_2, …, t_n (0 ≤ t_1 ≤ t_2 ≤ … ≤ t_n ≤ 10^9): the arrival times of the requests in milliseconds.
Output
Print n lines. The i-th line must be ACCEPT if the i-th request is accepted and REJECT otherwise.
Notes
In the first example k = 2 and w = 1000. The requests at 0 and 300 are accepted. At 999 the window (−1, 999] already holds two accepted requests, so it is rejected. At 1000 the window is (0, 1000]: the request at 0 has left it, only the one at 300 remains, so it is accepted. At 1300 the window (300, 1300] contains just the request at 1000 (the one at 300 is exactly w old and no longer counts), so it is accepted. At 1500 the window holds 1000 and 1300, so it is rejected.
In the second example all requests arrive at the same millisecond: the first three are accepted and the rest are rejected.