Instead of calculating your costs ahead of time, use a dynamic priority queue to account for any externalities as they occur and then punish or reward those in the queue accordingly.<p>You can construct priority functions to work as a FIFO queue or a LIFO stack if you&#x27;d like as well.