Solve equations using the $\max$ function How do you solve equations that involve the $\max$ function? For example:
$$\max(8-x, 0) + \max(272-x, 0) + \max(-100-x, 0) = 180$$
In this case, I can work out in my head that $x = 92.$ But what is the general procedure to use when the number of $\max$ terms are arbitrary? Thanks for the help, here is a Python solution for the problem if anyone is interested.
def solve_max(y, a):
    y = sorted(y)
    for idx, y1 in enumerate(y):
        y_left = y[idx:]
        y_sum = sum(y_left)
        x = (y_sum - a) / len(y_left)
        if x <= y1:
            return x
print solve_max([8, 272, -100], 180)


Here is the general solution for your max function. For example:
$$
\max(a_1 - b_1*x, c_1) + \max(a_2 - b_2*x, c_2) + \max(a_3 - b_3*x, c_3) = d
$$
solution steps(you can easily turn these into any programming language):
1. Calculate ratio threshhold for each max block.
$$
a_1 - b_1*x = c_1  \Rightarrow  r_1 = \frac{a_1-c_1}{b_1}
$$
2. Sort these ratios from small to large. suppose $r_1 \leq r_2 \leq r_3$
3. Initialize variables $a = \sum_{i=1}^3a_i, b=\sum_{i=1}^3b_i, a_0 = 0, b_0 =0,c_0 =0$
4. Iterate form $j = 0 \to 2$
 $a = a - a_j, b = b - b_j, d = d - c_j$
$x = \frac{a-d}{b}$
if $x \leq r_{i+1}$ break, we get the answer
else $j = j+1$  
