All problems
Two-Stage Recourse Value
Problem
Compute the expected second-stage recourse cost.
For each scenario with shortage scenario - x (floored at 0), the recourse buys the shortfall at unit cost. Return sum over scenarios of probs[k] * cost * max(0, scenarios[k] - x).
Hint
Only scenarios above the first-stage decision incur recourse.
Test cases
case 1
in: [5,[4,8],[0.5,0.5],2]
expected: 3
case 2
in: [10,[5,10],[0.5,0.5],1]
expected: 0
case 3
in: [0,[3],[1],4]
expected: 12
Starter codePython
def two_stage_recourse(x, scenarios, probs, cost):
# Your code here
pass3 test cases · run your code against them in the editor