Tomas has one free Saturday afternoon and several ways to spend it. For each option he knows its benefit (what it is worth to him, in euros: the wage for a shift, or the most he would pay to go to a concert) and its cost (the euros he must pay, such as a ticket). Its net value is benefit minus cost.
He can do only one thing. The opportunity cost of choosing an option is the net value of the best alternative he gives up: the highest net value among all the other options. Doing nothing is always possible and has net value 0, so an opportunity cost is never below 0.
Write afternoon(options) where options is a dict name -> (benefit, cost). Return a tuple (costs, best):
costs: a dict with the opportunity cost of every option;best: the name of the option with the highest net value, orNoneif no option has a net value above 0 (then doing nothing is best). If several options share the highest net value, return the name that comes first alphabetically.
Examples
Input: options = {"cafe shift": (48, 0), "concert": (70, 25), "study": (30, 0)}
Output: ({'cafe shift': 45, 'concert': 48, 'study': 48}, 'cafe shift')
Explanation: the net values are 48, 45 and 30. Taking the shift gives up the concert,
worth 45; going to the concert or studying gives up the shift, worth 48.
Input: options = {"lake trip": (20, 35)}
Output: ({'lake trip': 0}, None)
Explanation: the trip's net value is -15, so staying at home (0) is better.
Goals
- Compute each option's net value as its benefit minus its money cost
- Find the opportunity cost of a choice: the net value of the best alternative given up
- Remember that doing nothing is always an alternative, worth 0