A city bus card is tapped each time its owner boards a bus. You are given taps, the boarding
times of one day in minutes after midnight, in non-decreasing order. Write bus_charges(taps)
that returns a list with the amount charged, in cents, for each tap, applying these rules to the
taps in order:
- Double tap. A tap at most 1 minute after the last accepted tap is ignored (charge 0) and changes nothing. Every other tap is accepted.
- Transfer. An accepted tap is a free transfer (charge 0) if a journey is in progress, the tap is at most 90 minutes after that journey's first tap, and the journey has fewer than 3 accepted taps so far. It then joins that journey.
- New journey. Otherwise the tap starts a new journey. Its fare is 325 cents if the tap time
is in a peak window,
420 <= t < 540or960 <= t < 1110, and 250 cents otherwise. - Daily cap. The day's total may never exceed 800 cents. A new journey is charged
min(fare, 800 - total so far), so it may be charged less, or 0 once the cap is reached.
Examples
Input: taps = [480, 481, 530, 575]
Output: [325, 0, 0, 250]
Explanation: 481 is a double tap; 530 is a transfer; 575 is 95 minutes after 480.
Input: taps = [100, 150, 160, 170]
Output: [250, 0, 0, 250]
Explanation: the journey that began at 100 already has 3 taps when 170 arrives.
Input: taps = [430, 600, 1000, 1200]
Output: [325, 250, 225, 0]
Constraints
0 <= len(taps) <= 10000 <= taps[i] < 1440, and the list is sorted in non-decreasing order
Goals
- Simulate a set of fare rules tap by tap
- Keep the right pieces of state between iterations
- Apply rules in a precise order of priority