Loading page…
Greedy with a heap keeps the choices taken so far in a heap, and gives back the worst one when a limit is reached. Keep the three best fares of a stream with a min-heap; for parcels with deadlines, sort by deadline and give back the longest kept parcel when the clock is late. An exchange argument shows it is safe, and a rule that never gives back fails. The cost is O(n log n).
You work on the offers screen of a ride-hailing app.