Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def revenue_maximizing_spot_price(n, bids):
assert len(bids) <= n, "does not work when the number of bids exceeds n"
revenue, spot_price = max(
[ (sum([p for x in bids if x >= p]), p) for p in bids ])
return spot_price, revenue
if __name__ == '__main__':
print revenue_maximizing_spot_price(10, [ 1, 2, 5, 50 ])
# -> (50, 50)
print revenue_maximizing_spot_price(10, [ 1, 2, 5, 45, 50 ])
# -> (45, 90)
print revenue_maximizing_spot_price(10, [ 1, 2, 25, 45, 50 ])
# -> (45, 90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.