API Quota Manager
Your API service allocates k requests per user per calendar day. You need to process incoming API requests, track per-user daily quota consumption, and enforce rate limits.
Each request specifies a date and user ID. On each date, a user has exactly k requests available. If a request arrives for fewer requests than the user's remaining quota on that day, it is approved and the quota is consumed. Otherwise, it is rejected. When a new date arrives, the quota for all users resets to k.
For each request, output whether it was approved or rejected, along with the user's remaining quota on that date after the decision.
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9).
The next n lines each contain an integer date, an integer user, and an integer count (0 ≤ date ≤ 10^6, 0 ≤ user ≤ 10^6, 1 ≤ count ≤ 10^9). Dates are given in non-decreasing order within the input.
Output
For each request, print a line with either APPROVED or REJECTED, followed by the user's remaining quota on that date (in requests). The remaining quota is the quota after accounting for this request, whether it was approved or not.
Notes
- A request is approved if and only if the user's current remaining quota on that date is at least
count. - Quotas are per calendar day: each date has an independent quota pool of
krequests per user. - Users and dates may be sparse (not all IDs or dates are queried).
- Handle the constraints efficiently: a straightforward hash map solution suffices.