A subscription service runs a recurring daily promotion: every day is D seconds long, and any purchase whose time-of-day falls inside an inclusive peak window [lo, hi] (measured in seconds since the start of that day) unlocks a loyalty bonus for the subscriber who made it — but only if the purchase amount is also at least a minimum spend M. A subscriber earns the bonus for the whole log as soon as any single one of their purchases satisfies both conditions simultaneously.
Each purchase record gives a subscriber ID, an absolute timestamp in seconds (which may span many days), and a spend amount. The time-of-day of a purchase is its timestamp taken modulo D. Given all purchase records, count how many distinct subscriber IDs qualify for the bonus.
The first line contains five integers n, D, lo, hi, M.
Each of the next n lines contains three integers userId, timestamp, amount, describing one purchase. The same userId may appear on multiple lines.
Print a single integer: the number of distinct userId values with at least one purchase where (timestamp mod D) lies in [lo, hi] and amount >= M.
Example 1
Input
4 100 10 20 50 1 15 60 2 5 999 2 95 40 3 120 55
Expected
2
Explanation
Day length D=100, window [10,20], minimum spend 50. User 1's purchase has time-of-day 15%100=15 (in window) and amount 60>=50, so user 1 qualifies. User 2's purchases have time-of-day 5 and 95, neither in [10,20], so user 2 never qualifies even though 999>=50. User 3's purchase has time-of-day 120 mod 100 = 20 (in window) and amount 55>=50, so user 3 qualifies. Two distinct users (1 and 3) qualify, so the answer is 2.
Example 2
Input
3 50 0 0 100 7 0 100 8 50 100 9 1 100
Expected
2
Explanation
Day length D=50, window [0,0], minimum spend 100. User 7's time-of-day is 0%50=0 (in window) with amount 100>=100, qualifying. User 8's time-of-day is 50%50=0 (also in window) with amount 100>=100, qualifying. User 9's time-of-day is 1%50=1, which is outside the single-second window [0,0], so user 9 does not qualify. Two distinct users (7 and 8) qualify, so the answer is 2.
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 →