Let f(n) be the total cost of n textbooks.
If n≤10, then each textbook costs $50, so f(n)=50n.
If 10
If n>20, then the first 10 textbooks cost $50 each, the next 10 textbooks cost $40 each, and the remaining n−20 textbooks cost $30 each, so f(n)=500+700+30(n−20).
To find the number of textbooks you must buy for the average cost of a textbook to be $42, we solve the equation f(n)/n=42.
If n≤10, then f(n)/n=50n/n=50>42, so we can rule out this case.
If 10 42 for 10
If n>20, then f(n)/n=(500+400+30(n−20))/n=900/n+30(n−20)/n. Since 900/n is a decreasing function of n and 30(n−20)/n is an increasing function of n, the graph of f(n)/n is a parabola that opens downwards. The vertex of the parabola is at n=30, where f(n)/n=40. Since f(n)/n<42 for n<30 and f(n)/n→30 as n→∞, there must be a unique value of n>30 for which f(n)/n=42. We can find this value of n numerically.
Solving the equation f(n)/n=42 for n>30, we find that n≈33.33. Therefore, you must buy 34 textbooks for the average cost of a textbook to be $42.