Explanation:
Okay, so I need to find the largest value of 'a' such that the graph of y = f(x) intersects every horizontal line at least once. The function f(x) is piecewise defined: it's ax² when x is greater than or equal to a, and ax + 2a when x is less than a.

First, let me make sure I understand the problem. The question is about horizontal lines intersecting the graph of f(x) at least once. A horizontal line is of the form y = k, where k is a constant. So, for every horizontal line y = k, there must be at least one x such that f(x) = k. The task is to find the largest possible value of 'a' for which this condition holds.

So, essentially, the function f(x) must be surjective onto its range. Wait, but actually, the problem says "intersects every horizontal line at least once," which would mean that for every real number k, there exists an x such that f(x) = k. But maybe not? Wait, no. Wait, horizontal lines are y = k for any real number k. But if the function f(x) has a range that's not all real numbers, then there would be horizontal lines that don't intersect the graph. So, the problem is equivalent to saying that the range of f(x) is all real numbers. Therefore, we need the range of f(x) to be all real numbers. Therefore, we need to find the largest a such that f(x) is surjective onto ℝ.

But maybe not exactly. Wait, if the function is defined on all real numbers, but maybe its range is not all real numbers. For example, if the function has a maximum or minimum. So, if the function is surjective, then it must cover all real numbers. Therefore, the problem reduces to ensuring that the function f(x) can take on any real value. Therefore, we need to find the largest a such that the range of f(x) is all real numbers.

Alternatively, maybe there's another way to think about it. For every horizontal line y = k, there must be at least one x where f(x) = k. So, for each k, there exists x such that either:

1. If x ≥ a, then ax² = k, or
2. If x < a, then ax + 2a = k.

Therefore, for each k, there must be at least one solution in either of these two equations. Therefore, we need that for every k, either the equation ax² = k has a solution with x ≥ a, or the equation ax + 2a = k has a solution with x < a.

But since we need this to hold for all k, we need that for any k, at least one of these equations has a solution in the respective domain. Therefore, we need to ensure that the union of the ranges of the two pieces covers all real numbers. Therefore, the range of f(x) is the union of the range of ax² for x ≥ a and the range of ax + 2a for x < a. Therefore, we need that union to be all real numbers.

So, let me analyze the two pieces separately.

First, consider the piece where x < a: f(x) = ax + 2a. This is a linear function. Let me think about its range. If a ≠ 0, then this is a straight line with slope a. If a > 0, then as x approaches negative infinity, ax + 2a approaches negative infinity, and as x approaches a from the left, the value approaches a*a + 2a = a² + 2a. If a < 0, then as x approaches negative infinity, ax + 2a approaches positive infinity (since a is negative and x is going to negative infinity, so ax is positive infinity), and as x approaches a from the left, the value approaches a² + 2a. If a = 0, then f(x) = 0x + 0 = 0 for x < 0, so the range would be just {0} for that piece. But since we need the entire function to cover all real numbers, if a = 0, then the other piece is 0x² = 0 for x ≥ 0, so the entire function is 0 everywhere. Therefore, the range is {0}, which is not all real numbers. Therefore, a cannot be 0. So, a ≠ 0.

Therefore, assuming a ≠ 0, let's consider the linear part first. Let me think about the range of the linear part. For x < a, f(x) = ax + 2a. Let me write this as f(x) = a(x + 2). So, if a > 0, then as x approaches negative infinity, f(x) approaches negative infinity, and as x approaches a from the left, f(x) approaches a(a + 2). Therefore, the range of the linear part is (-∞, a(a + 2)) when a > 0. If a < 0, then as x approaches negative infinity, f(x) approaches positive infinity, and as x approaches a from the left, f(x) approaches a(a + 2). Therefore, the range of the linear part is (a(a + 2), ∞) when a < 0.

Now, the quadratic part: for x ≥ a, f(x) = ax². Let me analyze its range. The quadratic function ax². If a > 0, then ax² is a parabola opening upwards, with vertex at x = 0. However, the domain here is x ≥ a. So, if a > 0, then the minimum value of ax² on x ≥ a is at x = a, which is a*(a²) = a³. Therefore, the range of the quadratic part when a > 0 is [a³, ∞). If a < 0, then ax² is a parabola opening downward. However, since x ≥ a, and a is negative, the domain is x ≥ a (which includes all real numbers greater than or equal to a negative number). However, since the parabola opens downward, the maximum value occurs at x = 0 (if 0 is in the domain). Wait, but if a is negative, then x ≥ a includes x = 0. Therefore, the maximum value of ax² on x ≥ a is at x = 0, which is 0. Then, as x approaches infinity, ax² approaches negative infinity because a is negative. Therefore, the range of the quadratic part when a < 0 is (-∞, 0].

So, putting this together, the total range of f(x) is the union of the ranges of the two pieces. Let me consider different cases based on the sign of a.

Case 1: a > 0.

In this case, the linear part has range (-∞, a(a + 2)) and the quadratic part has range [a³, ∞). Therefore, the union of these two ranges is (-∞, a(a + 2)) ∪ [a³, ∞). For this union to be all real numbers, we need that the gap between a(a + 2) and a³ is covered. Wait, but if the union is (-∞, a(a + 2)) ∪ [a³, ∞), then for the union to be all real numbers, we need that a(a + 2) ≥ a³. Because if a(a + 2) ≥ a³, then the interval (-∞, a(a + 2)) includes up to a(a + 2), and [a³, ∞) starts at a³. If a(a + 2) ≥ a³, then the two intervals overlap or meet. Wait, but if a(a + 2) ≥ a³, then the upper bound of the linear part is greater than or equal to the lower bound of the quadratic part. Therefore, the union would be (-∞, ∞), because the linear part covers up to a(a + 2), and the quadratic part starts at a³. If a(a + 2) ≥ a³, then the quadratic part starts at a³ ≤ a(a + 2), so the union would be (-∞, ∞). Wait, but if a(a + 2) ≥ a³, then the upper bound of the linear part is higher than the lower bound of the quadratic part, so there is no gap. Therefore, the union is all real numbers. However, if a(a + 2) < a³, then there is a gap between a(a + 2) and a³, so the union would not cover all real numbers. Therefore, for the union to be all real numbers, we need a(a + 2) ≥ a³. Let me solve this inequality for a > 0.

So, a(a + 2) ≥ a³.

Divide both sides by a (since a > 0, we can divide without changing inequality direction):

a + 2 ≥ a²

Rearranged:

a² - a - 2 ≤ 0

Solving the quadratic inequality a² - a - 2 ≤ 0.

First, find roots of a² - a - 2 = 0.

Using quadratic formula: a = [1 ± sqrt(1 + 8)] / 2 = [1 ± 3]/2. Therefore, roots are (1 + 3)/2 = 2 and (1 - 3)/2 = -1.

Since the quadratic coefficient is positive, the quadratic is ≤ 0 between its roots. Therefore, the inequality a² - a - 2 ≤ 0 holds for a ∈ [-1, 2]. However, in this case, we are considering a > 0, so the solution is a ∈ (0, 2].

Therefore, for a > 0, the condition that the union of the ranges is all real numbers is satisfied when a ∈ (0, 2]. Therefore, if a is in (0, 2], then the function f(x) covers all real numbers. However, if a > 2, then the inequality a(a + 2) ≥ a³ becomes false, so there is a gap between a(a + 2) and a³, meaning that the union of the ranges does not cover all real numbers. Therefore, for a > 2, the function f(x) does not intersect every horizontal line. Therefore, for a > 2, there are horizontal lines that are not intersected by the graph. Therefore, the maximum value of a in this case is 2.

But wait, let me check for a = 2. Let me verify if when a = 2, the union of the ranges is indeed all real numbers.

For a = 2:

Linear part: x < 2, f(x) = 2x + 4. The range is (-∞, 2*(2) + 4) = (-∞, 8). Wait, no. Wait, earlier I said for a > 0, the linear part has range (-∞, a(a + 2)). For a = 2, that would be (-∞, 2*(2 + 2)) = (-∞, 8). The quadratic part for x ≥ 2 is f(x) = 2x², which has range [2*(2)^2, ∞) = [8, ∞). Therefore, the union is (-∞, 8) ∪ [8, ∞) = (-∞, ∞). Therefore, yes, when a = 2, the union is all real numbers. Therefore, a = 2 is acceptable.

But if a > 2, say a = 3. Then, linear part: x < 3, f(x) = 3x + 6. The range is (-∞, 3*(3) + 6) = (-∞, 15). The quadratic part for x ≥ 3 is f(x) = 3x², which has range [3*(3)^2, ∞) = [27, ∞). Therefore, the union is (-∞, 15) ∪ [27, ∞). Therefore, there is a gap between 15 and 27. Therefore, horizontal lines between 15 and 27 would not be intersected by the graph. Therefore, for a > 2, the function does not cover all real numbers. Therefore, the maximum a in this case is 2.

But wait, the problem says "the largest value of a". However, we need to check the case when a < 0 as well. Because maybe for some negative a, the function could cover all real numbers? Let me check.

Case 2: a < 0.

In this case, the linear part is f(x) = ax + 2a for x < a. Since a < 0, the linear function has slope a < 0. Therefore, as x approaches negative infinity, ax + 2a approaches positive infinity (since a is negative and x is going to negative infinity, so ax is positive infinity). As x approaches a from the left, the value approaches a*a + 2a = a² + 2a. Therefore, the range of the linear part is (a² + 2a, ∞).

The quadratic part is f(x) = ax² for x ≥ a. Since a < 0, the quadratic function ax² opens downward. The domain is x ≥ a. Since a is negative, x ≥ a includes all real numbers greater than or equal to a negative number. The maximum value of ax² occurs at x = 0 (since the vertex of ax² is at x = 0, and since a < 0, it's a maximum). However, x = 0 is in the domain x ≥ a only if 0 ≥ a, which is true because a is negative. Therefore, the maximum value of ax² is at x = 0, which is a*(0)^2 = 0. As x approaches infinity, ax² approaches negative infinity. Therefore, the range of the quadratic part is (-∞, 0].

Therefore, the union of the ranges is (a² + 2a, ∞) ∪ (-∞, 0]. For this union to be all real numbers, we need that (a² + 2a, ∞) ∪ (-∞, 0] = ℝ. Therefore, the overlap between these two intervals must cover the entire real line. However, the interval (-∞, 0] covers up to 0, and (a² + 2a, ∞) starts at a² + 2a. Therefore, to have the union be all real numbers, we need that the lower bound of the linear part (a² + 2a) is less than or equal to 0. Because if a² + 2a ≤ 0, then (a² + 2a, ∞) would start at some value less than or equal to 0, so the union would be (-∞, 0] ∪ (a² + 2a, ∞). If a² + 2a ≤ 0, then (a² + 2a, ∞) would cover from some value less than or equal to 0 to infinity. However, since (-∞, 0] is already there, the union would be (-∞, ∞) only if (a² + 2a, ∞) covers from some value less than or equal to 0 to infinity. Wait, but if a² + 2a ≤ 0, then (a² + 2a, ∞) includes all numbers greater than a² + 2a, which is less than or equal to 0. Therefore, the union would be (-∞, 0] ∪ (a² + 2a, ∞). However, since a² + 2a ≤ 0, then (a² + 2a, ∞) includes (a² + 2a, 0] and (0, ∞). Therefore, the union would be (-∞, ∞). Wait, but (-∞, 0] ∪ (a² + 2a, ∞) would be (-∞, ∞) if a² + 2a ≤ 0. Because if a² + 2a is less than or equal to 0, then (a² + 2a, ∞) includes all numbers greater than a² + 2a, which includes (a² + 2a, 0] and (0, ∞). Therefore, combining with (-∞, 0], the entire real line is covered. Therefore, for a < 0, if a² + 2a ≤ 0, then the union of the ranges is all real numbers. Therefore, we need to solve a² + 2a ≤ 0 for a < 0.

Solving a² + 2a ≤ 0:

Factor: a(a + 2) ≤ 0.

This inequality holds when a ∈ [-2, 0]. However, since we are in the case a < 0, the solution is a ∈ [-2, 0).

Therefore, for a ∈ [-2, 0), the union of the ranges is all real numbers. Therefore, for these values of a, the function f(x) intersects every horizontal line. However, the problem asks for the largest value of a. So, in the case of a < 0, the maximum a is approaching 0 from the left. However, in the case of a > 0, the maximum a is 2. Therefore, comparing 2 and 0, the largest value of a is 2. Therefore, the answer is 2?

Wait, but let me check if there's a possibility that for some a between 0 and 2, maybe there's a higher value? Wait, no. For a > 0, the maximum a is 2. For a < 0, the maximum a is approaching 0. Therefore, 2 is larger than 0. Therefore, the answer is 2. However, let me check if there's a mistake here.

Wait, but let me think again. For a < 0, the maximum a is approaching 0. But if a is approaching 0 from the negative side, then the function f(x) would be... Let me take a = -1, which is in [-2, 0). Let me check if the function covers all real numbers. For a = -1:

Linear part: x < -1, f(x) = -1*x + 2*(-1) = -x - 2. The range is (a² + 2a, ∞) = ((-1)^2 + 2*(-1), ∞) = (1 - 2, ∞) = (-1, ∞). The quadratic part: x ≥ -1, f(x) = -1*x². The range is (-∞, 0]. Therefore, the union is (-∞, 0] ∪ (-1, ∞) = (-∞, ∞). Therefore, yes, it covers all real numbers. Similarly, for a approaching 0 from the left, say a = -ε where ε is a small positive number. Then, the linear part's range is (a² + 2a, ∞) = (ε² - 2ε, ∞). Since ε is small, ε² - 2ε ≈ -2ε, which is approaching 0 from below. Therefore, the linear part's range is (-2ε, ∞), and the quadratic part's range is (-∞, 0]. Therefore, the union is (-∞, ∞). Therefore, for any a in [-2, 0), the function covers all real numbers. Therefore, the maximum a in this case is approaching 0. However, since we are to find the largest value of a, which is 2 in the positive case. Therefore, 2 is larger than 0, so the answer is 2.

But let me check if there's a case where a is between 0 and 2, but maybe for some reason, the function doesn't cover all real numbers? Wait, no. For a between 0 and 2, the union of the ranges is (-∞, a(a + 2)) ∪ [a³, ∞). Since a(a + 2) ≥ a³ (as we saw earlier for a ∈ (0, 2]), then the union is all real numbers. Therefore, for a between 0 and 2, the function covers all real numbers. Therefore, the maximum a is 2. Therefore, the answer is 2.

But let me check for a = 2, as before. For a = 2, the linear part is x < 2, f(x) = 2x + 4, which has range (-∞, 8). The quadratic part is x ≥ 2, f(x) = 2x², which has range [8, ∞). Therefore, union is all real numbers. Therefore, yes, a = 2 is acceptable.

But let me check if there's a case where even for a > 2, maybe the function still covers all real numbers? For example, suppose a = 3. Then, the linear part is x < 3, f(x) = 3x + 6, which has range (-∞, 15). The quadratic part is x ≥ 3, f(x) = 3x², which has range [27, ∞). Therefore, the union is (-∞, 15) ∪ [27, ∞). Therefore, there is a gap between 15 and 27. Therefore, horizontal lines between 15 and 27 are not intersected. Therefore, the function does not cover all real numbers. Therefore, a = 3 is invalid.

But what if a is negative? For example, a = -2. Let me check. For a = -2:

Linear part: x < -2, f(x) = -2x + 2*(-2) = -2x - 4. The range is (a² + 2a, ∞) = ((-2)^2 + 2*(-2), ∞) = (4 - 4, ∞) = (0, ∞). The quadratic part: x ≥ -2, f(x) = -2x². The range is (-∞, 0]. Therefore, the union is (-∞, 0] ∪ (0, ∞) = ℝ \ {0}. Wait, but there is a problem here. The union is (-∞, 0] ∪ (0, ∞), which is all real numbers except 0. Therefore, the horizontal line y = 0 is not intersected? Wait, but let me check if y = 0 is achieved.

For the quadratic part, f(x) = -2x². When is this equal to 0? When x² = 0, i.e., x = 0. Since x ≥ -2, x = 0 is in the domain. Therefore, f(0) = -2*(0)^2 = 0. Therefore, y = 0 is achieved at x = 0. Therefore, the union is actually (-∞, ∞). Wait, because (-∞, 0] includes 0, and (0, ∞) includes numbers greater than 0. Therefore, the union is (-∞, ∞). Therefore, for a = -2, the function covers all real numbers. Therefore, even though the linear part's range is (0, ∞) and the quadratic part's range is (-∞, 0], the union is all real numbers. Therefore, a = -2 is acceptable. However, for a = -2, which is less than 0, but the maximum a in the negative case is approaching 0. Therefore, the maximum a overall is 2.

But let me check for a = -2. The function f(x) is:

For x ≥ -2: f(x) = -2x².

For x < -2: f(x) = -2x - 4.

So, for example, if I want to solve f(x) = k for any k.

If k is in (-∞, 0], then there is a solution in the quadratic part (since the quadratic part covers (-∞, 0]).

If k is in (0, ∞), then there is a solution in the linear part (since the linear part covers (0, ∞)). Therefore, yes, all real numbers are covered. Therefore, a = -2 is acceptable. However, the problem asks for the largest value of a. Since a = 2 is larger than a = -2, the answer is 2.

But let me check if there is a value of a between 2 and something else? Wait, no. For a > 2, as we saw, there is a gap. Therefore, 2 is the maximum.

But let me think again. Is there a possibility that for some a > 2, even though there is a gap between a(a + 2) and a³, maybe the quadratic part can still cover that gap? Wait, no. Because for a > 0, the quadratic part is [a³, ∞), and the linear part is (-∞, a(a + 2)). Therefore, if a(a + 2) < a³, then the gap is between a(a + 2) and a³. Therefore, there is no way for the function to cover that gap. Therefore, the function cannot cover those values. Therefore, for a > 2, the function does not cover all real numbers. Therefore, 2 is indeed the maximum.

But let me check for a = 2, the gap is exactly at the point where the two ranges meet. For a = 2, the linear part goes up to 8, and the quadratic part starts at 8. Therefore, there is no gap. Therefore, the function covers all real numbers.

Therefore, the answer is 2. However, let me check if there's another case where maybe the function can cover all real numbers for some a > 2. Suppose someone says, maybe if the quadratic part can reach lower values? Wait, for a > 0, the quadratic part is ax² for x ≥ a. Since a > 0, ax² is increasing for x ≥ 0. Therefore, the minimum value of the quadratic part is at x = a, which is a³. Therefore, the quadratic part cannot go below a³. Therefore, if a³ is greater than a(a + 2), then there is a gap. Therefore, for a > 2, a³ > a(a + 2). Therefore, the quadratic part starts above the linear part's upper bound, creating a gap. Therefore, no way to cover that gap. Therefore, 2 is indeed the maximum.

But let me check for a = 1. For a = 1, which is less than 2. Then, linear part: x < 1, f(x) = x + 2. The range is (-∞, 1*(1) + 2) = (-∞, 3). The quadratic part: x ≥ 1, f(x) = x². The range is [1, ∞). Therefore, the union is (-∞, 3) ∪ [1, ∞) = (-∞, ∞). Therefore, yes, covers all real numbers. Therefore, for a = 1, it works. For a = 2, same thing. For a = 2.5, which is greater than 2, the linear part's upper bound is 2.5*(2.5 + 2) = 2.5*4.5 = 11.25. The quadratic part starts at (2.5)^3 = 15.625. Therefore, the gap between 11.25 and 15.625. Therefore, horizontal lines between 11.25 and 15.625 are not covered. Therefore, the function does not cover all real numbers. Therefore, a = 2 is the maximum.

But let me check if there's another way to approach this problem. Maybe by considering continuity or something else?

Wait, the function is piecewise defined. At x = a, the function has a value of f(a) = a*(a)^2 = a³ from the quadratic part, and from the linear part, approaching x = a from the left, the limit is a*a + 2a = a² + 2a. Therefore, for the function to be continuous at x = a, we need a³ = a² + 2a. Let me solve this equation:

a³ = a² + 2a

a³ - a² - 2a = 0

a(a² - a - 2) = 0

Therefore, a = 0 or a² - a - 2 = 0. The solutions to a² - a - 2 = 0 are a = [1 ± sqrt(1 + 8)] / 2 = [1 ± 3]/2, so a = 2 or a = -1. Therefore, the function is continuous at x = a when a = 0, 2, or -1. However, we already saw that a = 0 is not acceptable because the function becomes zero everywhere. However, for a = 2 or a = -1, the function is continuous at x = a. However, continuity at x = a is not necessary for the function to intersect every horizontal line. However, maybe the continuity is related to the coverage of the range?

But in our previous analysis, we saw that for a = 2, the function is continuous at x = a (since a³ = 8 and a² + 2a = 4 + 4 = 8). Therefore, the function is continuous at x = 2. However, for a = -1, the function is continuous at x = -1. Let me check for a = -1. For a = -1, the linear part approaches x = -1 from the left: f(x) approaches (-1)^2 + 2*(-1) = 1 - 2 = -1. The quadratic part at x = -1 is f(-1) = (-1)*(-1)^2 = -1. Therefore, continuous. However, for a = -1, the function covers all real numbers, as we saw earlier. However, the maximum a in the negative case is approaching 0, so 2 is still larger.

But maybe there's a different approach. Let me think. For the function to intersect every horizontal line, it must be that for any real number k, there exists an x such that f(x) = k. Therefore, for each k, there must be a solution to either ax² = k with x ≥ a or ax + 2a = k with x < a.

Let me consider solving these equations.

First, for the quadratic equation: ax² = k with x ≥ a. So, solving for x:

x = ±√(k/a). However, since x ≥ a, we need to check if √(k/a) ≥ a or -√(k/a) ≥ a. But this depends on the sign of a and the value of k.

Similarly, for the linear equation: ax + 2a = k => x = (k - 2a)/a = (k/a) - 2. And we need x < a. Therefore, (k/a) - 2 < a => k/a < a + 2 => k < a(a + 2) if a > 0, or k > a(a + 2) if a < 0. Wait, let me check:

From x < a:

(k/a) - 2 < a

Multiply both sides by a. However, the direction of inequality depends on the sign of a.

Case 1: a > 0.

Then, multiplying both sides by a (positive, so inequality direction remains):

k - 2a < a² => k < a² + 2a.

Case 2: a < 0.

Multiplying both sides by a (negative, so inequality direction reverses):

k - 2a > a² => k > a² + 2a.

Therefore, for the linear equation to have a solution x < a, we need:

If a > 0: k < a(a + 2)

If a < 0: k > a(a + 2)

Therefore, for the linear part to cover certain k's, depending on the sign of a.

Similarly, for the quadratic equation ax² = k with x ≥ a.

Let me analyze this.

First, solving ax² = k => x² = k/a. Therefore, real solutions exist only if k/a ≥ 0. Therefore, k and a must have the same sign.

Case 1: a > 0.

Then, k must be ≥ 0. Then, x = ±√(k/a). However, we need x ≥ a. Therefore, we need either √(k/a) ≥ a or -√(k/a) ≥ a. But since a > 0, -√(k/a) is negative, and since a > 0, -√(k/a) ≥ a would imply that a negative number is ≥ a positive number, which is impossible. Therefore, only √(k/a) ≥ a is possible. Therefore, √(k/a) ≥ a => k/a ≥ a² => k ≥ a³. Therefore, for a > 0, the quadratic equation has a solution x ≥ a if and only if k ≥ a³. Therefore, the quadratic part covers k ≥ a³.

Case 2: a < 0.

Then, k must be ≤ 0 (since k/a ≥ 0 and a < 0). Then, x² = k/a. Since k ≤ 0 and a < 0, k/a ≥ 0. Therefore, x = ±√(k/a). Now, we need x ≥ a. Since a < 0, and x can be positive or negative. Let me check:

If x = √(k/a), which is non-negative, then since a < 0, we need √(k/a) ≥ a. Since √(k/a) is non-negative and a is negative, this inequality is always true. Therefore, for any k ≤ 0, x = √(k/a) is a solution with x ≥ a (since x ≥ 0 ≥ a). Therefore, for a < 0, the quadratic equation ax² = k has a solution x ≥ a for any k ≤ 0. Additionally, the other solution x = -√(k/a) is negative. However, since a < 0, we need to check if -√(k/a) ≥ a. Let me see:

Let me denote t = -√(k/a). Since k ≤ 0 and a < 0, k/a ≥ 0, so t is real. Then, t = -√(k/a). Since √(k/a) ≥ 0, t ≤ 0. Therefore, t is negative or zero. Since a < 0, we need t ≥ a. Since t is negative and a is negative, this is equivalent to t ≥ a. However, since t = -√(k/a), which is a specific value. However, since we already have a solution x = √(k/a) ≥ a, the other solution x = -√(k/a) may or may not satisfy x ≥ a. However, since we only need at least one solution, the existence of x = √(k/a) is sufficient. Therefore, for a < 0, the quadratic equation covers all k ≤ 0.

Therefore, summarizing:

For a > 0:

- The linear part covers k < a(a + 2)
- The quadratic part covers k ≥ a³
Therefore, to cover all real numbers, we need that the union of (-∞, a(a + 2)) and [a³, ∞) is ℝ. Which requires that a(a + 2) ≥ a³, leading to a ∈ (0, 2].

For a < 0:

- The linear part covers k > a(a + 2)
- The quadratic part covers k ≤ 0
Therefore, the union is (-∞, 0] ∪ (a(a + 2), ∞). To cover all real numbers, we need that (a(a + 2), ∞) covers from some value less than or equal to 0 to infinity. Therefore, a(a + 2) ≤ 0, leading to a ∈ [-2, 0).

Therefore, combining both cases, the maximum value of a is 2.

Therefore, the answer is \boxed{2}.

**Final Answer**
\boxed{2}

To determine the **largest value of $ a $** such that the graph of the function
$$
f(x) =
\begin{cases}
ax^2 & \text{if } x \geq a,\\
ax + 2a & \text{if } x < a,
\end{cases}
$$
intersects **every horizontal line at least once**, we need to ensure that the function is **surjective** onto the real numbers $ \mathbb{R} $. That is, for **every real number $ k $**, there must exist at least one $ x $ such that $ f(x) = k $.

---

### Step 1: Analyze the Function's Behavior

We consider the function in two parts:

- **Quadratic part**: $ f(x) = ax^2 $ for $ x \geq a $
- **Linear part**: $ f(x) = ax + 2a $ for $ x < a $

We'll analyze the **range** of each part and then determine the **union of their ranges**.

---

### Step 2: Analyze the Quadratic Part

- For $ x \geq a $, the function is $ f(x) = ax^2 $
- If $ a > 0 $, this is a parabola opening upwards, and the minimum value occurs at $ x = a $, giving $ f(a) = a^3 $
- So, the range is $ [a^3, \infty) $

- If $ a < 0 $, the parabola opens downward, and the maximum value occurs at $ x = 0 $, giving $ f(0) = 0 $
- So, the range is $ (-\infty, 0] $

---

### Step 3: Analyze the Linear Part

- For $ x < a $, the function is $ f(x) = ax + 2a = a(x + 2) $
- If $ a > 0 $, the function is increasing, and as $ x \to -\infty $, $ f(x) \to -\infty $, and as $ x \to a^- $, $ f(x) \to a(a + 2) $
- So, the range is $ (-\infty, a(a + 2)) $

- If $ a < 0 $, the function is decreasing, and as $ x \to -\infty $, $ f(x) \to \infty $, and as $ x \to a^- $, $ f(x) \to a(a + 2) $
- So, the range is $ (a(a + 2), \infty) $

---

### Step 4: Determine When the Union of Ranges Covers $ \mathbb{R} $

We now consider the union of the two ranges:

- **Case 1: $ a > 0 $**
  - Quadratic part: $ [a^3, \infty) $
  - Linear part: $ (-\infty, a(a + 2)) $
  - Union: $ (-\infty, a(a + 2)) \cup [a^3, \infty) $

  For the union to be $ \mathbb{R} $, we must have:
  $$
  a(a + 2) \geq a^3
  $$
  Simplify:
  $$
  a^2 + 2a \geq a^3 \Rightarrow a^3 - a^2 - 2a \leq 0 \Rightarrow a(a^2 - a - 2) \leq 0
  $$
  Solve the inequality:
  $$
  a(a - 2)(a + 1) \leq 0
  $$
  The roots are $ a = 0, 2, -1 $. The inequality holds for:
  $$
  a \in [-1, 0] \cup [0, 2]
  $$
  Since we are considering $ a > 0 $, the valid interval is:
  $$
  a \in (0, 2]
  $$

- **Case 2: $ a < 0 $**
  - Quadratic part: $ (-\infty, 0] $
  - Linear part: $ (a(a + 2), \infty) $
  - Union: $ (-\infty, 0] \cup (a(a + 2), \infty) $

  For the union to be $ \mathbb{R} $, we must have:
  $$
  a(a + 2) \leq 0
  $$
  Solve:
  $$
  a(a + 2) \leq 0 \Rightarrow a \in [-2, 0]
  $$

---

### Step 5: Determine the Largest Value of $ a $

- From Case 1: $ a \in (0, 2] $
- From Case 2: $ a \in [-2, 0) $

The **largest value of $ a $** that satisfies the condition is:
$$
\boxed{2}
$$

This value ensures that the union of the ranges of the two parts of the function covers all real numbers, and thus the graph intersects every horizontal line at least once.

---

### Final Answer

$$
\boxed{2}
$$

[Assistant]
Explanation:
Okay, so I need to find the largest value of 'a' such that the graph of y = f(x) intersects every horizontal line at least once. The function f(x) is piecewise defined: it's ax² when x is greater than or equal to a, and ax + 2a when x is less than a.

First, let me make sure I understand the problem. The question is about horizontal lines intersecting the graph of f(x) at least once. A horizontal line is of the form y = k, where k is a constant. So, for every horizontal line y = k, there must be at least one x such that f(x) = k. The task is to find the largest possible value of 'a' for which this condition holds.

So, essentially, the function f(x) must be surjective onto its range. Wait, but actually, the problem says "intersects every horizontal line at least once," which would mean that for every real number k, there exists an x such that f(x) = k. But maybe not? Wait, no. Wait, horizontal lines are y = k for any real number k. But if the function f(x) has a range that's not all real numbers, then there would be horizontal lines that don't intersect the graph. So, the problem is equivalent to saying that the range of f(x) is all real numbers. Therefore, we need the range of f(x) to be all real numbers. Therefore, we need to find the largest a such that f(x) is surjective onto ℝ.

But maybe not exactly. Wait, if the function is defined on all real numbers, but maybe its range is not all real numbers. For example, if the function has a maximum or minimum. So, if the function is surjective, then it must cover all real numbers. Therefore, the problem reduces to ensuring that the function f(x) can take on any real value. Therefore, we need to find the largest a such that the range of f(x) is all real numbers.

Alternatively, maybe there's another way to think about it. For every horizontal line y = k, there must be at least one x where f(x) = k. So, for each k, there exists x such that either:

1. If x ≥ a, then ax² = k, or
2. If x < a, then ax + 2a = k.

Therefore, for each k, there must be at least one solution in either of these two equations. Therefore, we need that for every k, either the equation ax² = k has a solution with x ≥ a, or the equation ax + 2a = k has a solution with x < a.

But since we need this to hold for all k, we need that for any k, at least one of these equations has a solution in the respective domain. Therefore, we need to ensure that the union of the ranges of the two pieces covers all real numbers. Therefore, the range of f(x) is the union of the range of ax² for x ≥ a and the range of ax + 2a for x < a. Therefore, we need that union to be all real numbers.

So, let me analyze the two pieces separately.

First, consider the piece where x < a: f(x) = ax + 2a. This is a linear function. Let me think about its range. If a ≠ 0, then this is a straight line with slope a. If a > 0, then as x approaches negative infinity, ax + 2a approaches negative infinity, and as x approaches a from the left, the value approaches a*a + 2a = a² + 2a. If a < 0, then as x approaches negative infinity, ax + 2a approaches positive infinity (since a is negative and x is going to negative infinity, so ax is positive infinity), and as x approaches a from the left, the value approaches a² + 2a. If a = 0, then f(x) = 0x + 0 = 0 for x < 0, so the range would be just {0} for that piece. But since we need the entire function to cover all real numbers, if a = 0, then the other piece is 0x² = 0 for x ≥ 0, so the entire function is 0 everywhere. Therefore, the range is {0}, which is not all real numbers. Therefore, a cannot be 0. So, a ≠ 0.

Therefore, assuming a ≠ 0, let's consider the linear part first. Let me think about the range of the linear part. For x < a, f(x) = ax + 2a. Let me write this as f(x) = a(x + 2). So, if a > 0, then as x approaches negative infinity, f(x) approaches negative infinity, and as x approaches a from the left, f(x) approaches a(a + 2). Therefore, the range of the linear part is (-∞, a(a + 2)) when a > 0. If a < 0, then as x approaches negative infinity, f(x) approaches positive infinity, and as x approaches a from the left, f(x) approaches a(a + 2). Therefore, the range of the linear part is (a(a + 2), ∞) when a < 0.

Now, the quadratic part: for x ≥ a, f(x) = ax². Let me analyze its range. The quadratic function ax². If a > 0, then ax² is a parabola opening upwards, with vertex at x = 0. However, the domain here is x ≥ a. So, if a > 0, then the minimum value of ax² on x ≥ a is at x = a, which is a*(a²) = a³. Therefore, the range of the quadratic part when a > 0 is [a³, ∞). If a < 0, then ax² is a parabola opening downward. However, since x ≥ a, and a is negative, the domain is x ≥ a (which includes all real numbers greater than or equal to a negative number). However, since the parabola opens downward, the maximum value occurs at x = 0 (if 0 is in the domain). Wait, but if a is negative, then x ≥ a includes x = 0. Therefore, the maximum value of ax² on x ≥ a is at x = 0, which is 0. Then, as x approaches infinity, ax² approaches negative infinity because a is negative. Therefore, the range of the quadratic part when a < 0 is (-∞, 0].

So, putting this together, the total range of f(x) is the union of the ranges of the two pieces. Let me consider different cases based on the sign of a.

Case 1: a > 0.

In this case, the linear part has range (-∞, a(a + 2)) and the quadratic part has range [a³, ∞). Therefore, the union of these two ranges is (-∞, a(a + 2)) ∪ [a³, ∞). For this union to be all real numbers, we need that the gap between a(a + 2) and a³ is covered. Wait, but if the union is (-∞, a(a + 2)) ∪ [a³, ∞), then for the union to be all real numbers, we need that a(a + 2) ≥ a³. Because if a(a + 2) ≥ a³, then the interval (-∞, a(a + 2)) includes up to a(a + 2), and [a³, ∞) starts at a³. If a(a + 2) ≥ a³, then the two intervals overlap or meet. Wait, but if a(a + 2) ≥ a³, then the upper bound of the linear part is greater than or equal to the lower bound of the quadratic part. Therefore, the union would be (-∞, ∞), because the linear part covers up to a(a + 2), and the quadratic part starts at a³. If a(a + 2) ≥ a³, then the quadratic part starts at a³ ≤ a(a + 2), so the union would be (-∞, ∞). Wait, but if a(a + 2) ≥ a³, then the upper bound of the linear part is higher than the lower bound of the quadratic part, so there is no gap. Therefore, the union is all real numbers. However, if a(a + 2) < a³, then there is a gap between a(a + 2) and a³, so the union would not cover all real numbers. Therefore, for the union to be all real numbers, we need a(a + 2) ≥ a³. Let me solve this inequality for a > 0.

So, a(a + 2) ≥ a³.

Divide both sides by a (since a > 0, we can divide without changing inequality direction):

a + 2 ≥ a²

Rearranged:

a² - a - 2 ≤ 0

Solving the quadratic inequality a² - a - 2 ≤ 0.

First, find roots of a² - a - 2 = 0.

Using quadratic formula: a = [1 ± sqrt(1 + 8)] / 2 = [1 ± 3]/2. Therefore, roots are (1 + 3)/2 = 2 and (1 - 3)/2 = -1.

Since the quadratic coefficient is positive, the quadratic is ≤ 0 between its roots. Therefore, the inequality a² - a - 2 ≤ 0 holds for a ∈ [-1, 2]. However, in this case, we are considering a > 0, so the solution is a ∈ (0, 2].

Therefore, for a > 0, the condition that the union of the ranges is all real numbers is satisfied when a ∈ (0, 2]. Therefore, if a is in (0, 2], then the function f(x) covers all real numbers. However, if a > 2, then the inequality a(a + 2) ≥ a³ becomes false, so there is a gap between a(a + 2) and a³, meaning that the union of the ranges does not cover all real numbers. Therefore, for a > 2, the function f(x) does not intersect every horizontal line. Therefore, for a > 2, there are horizontal lines that are not intersected by the graph. Therefore, the maximum value of a in this case is 2.

But wait, let me check for a = 2. Let me verify if when a = 2, the union of the ranges is indeed all real numbers.

For a = 2:

Linear part: x < 2, f(x) = 2x + 4. The range is (-∞, 2*(2) + 4) = (-∞, 8). Wait, no. Wait, earlier I said for a > 0, the linear part has range (-∞, a(a + 2)). For a = 2, that would be (-∞, 2*(2 + 2)) = (-∞, 8). The quadratic part for x ≥ 2 is f(x) = 2x², which has range [2*(2)^2, ∞) = [8, ∞). Therefore, the union is (-∞, 8) ∪ [8, ∞) = (-∞, ∞). Therefore, yes, when a = 2, the union is all real numbers. Therefore, a = 2 is acceptable.

But if a > 2, say a = 3. Then, linear part: x < 3, f(x) = 3x + 6. The range is (-∞, 3*(3) + 6) = (-∞, 15). The quadratic part for x ≥ 3 is f(x) = 3x², which has range [3*(3)^2, ∞) = [27, ∞). Therefore, the union is (-∞, 15) ∪ [27, ∞). Therefore, there is a gap between 15 and 27. Therefore, horizontal lines between 15 and 27 would not be intersected by the graph. Therefore, for a > 2, the function does not cover all real numbers. Therefore, the maximum a in this case is 2.

But wait, the problem says "the largest value of a". However, we need to check the case when a < 0 as well. Because maybe for some negative a, the function could cover all real numbers? Let me check.

Case 2: a < 0.

In this case, the linear part is f(x) = ax + 2a for x < a. Since a < 0, the linear function has slope a < 0. Therefore, as x approaches negative infinity, ax + 2a approaches positive infinity (since a is negative and x is going to negative infinity, so ax is positive infinity). As x approaches a from the left, the value approaches a*a + 2a = a² + 2a. Therefore, the range of the linear part is (a² + 2a, ∞).

The quadratic part is f(x) = ax² for x ≥ a. Since a < 0, the quadratic function ax² opens downward. The domain is x ≥ a. Since a is negative, x ≥ a includes all real numbers greater than or equal to a negative number. The maximum value of ax² occurs at x = 0 (since the vertex of ax² is at x = 0, and since a < 0, it's a maximum). However, x = 0 is in the domain x ≥ a only if 0 ≥ a, which is true because a is negative. Therefore, the maximum value of ax² is at x = 0, which is a*(0)^2 = 0. As x approaches infinity, ax² approaches negative infinity. Therefore, the range of the quadratic part is (-∞, 0].

Therefore, the union of the ranges is (a² + 2a, ∞) ∪ (-∞, 0]. For this union to be all real numbers, we need that (a² + 2a, ∞) ∪ (-∞, 0] = ℝ. Therefore, the overlap between these two intervals must cover the entire real line. However, the interval (-∞, 0] covers up to 0, and (a² + 2a, ∞) starts at a² + 2a. Therefore, to have the union be all real numbers, we need that the lower bound of the linear part (a² + 2a) is less than or equal to 0. Because if a² + 2a ≤ 0, then (a² + 2a, ∞) would start at some value less than or equal to 0, so the union would be (-∞, 0] ∪ (a² + 2a, ∞). If a² + 2a ≤ 0, then (a² + 2a, ∞) would cover from some value less than or equal to 0 to infinity. However, since (-∞, 0] is already there, the union would be (-∞, ∞) only if (a² + 2a, ∞) covers from some value less than or equal to 0 to infinity. Wait, but if a² + 2a ≤ 0, then (a² + 2a, ∞) includes all numbers greater than a² + 2a, which is less than or equal to 0. Therefore, the union would be (-∞, 0] ∪ (a² + 2a, ∞). However, since a² + 2a ≤ 0, then (a² + 2a, ∞) includes (a² + 2a, 0] and (0, ∞). Therefore, the union would be (-∞, ∞). Wait, but (-∞, 0] ∪ (a² + 2a, ∞) would be (-∞, ∞) if a² + 2a ≤ 0. Because if a² + 2a is less than or equal to 0, then (a² + 2a, ∞) includes all numbers greater than a² + 2a, which includes (a² + 2a, 0] and (0, ∞). Therefore, combining with (-∞, 0], the entire real line is covered. Therefore, for a < 0, if a² + 2a ≤ 0, then the union of the ranges is all real numbers. Therefore, we need to solve a² + 2a ≤ 0 for a < 0.

Solving a² + 2a ≤ 0:

Factor: a(a + 2) ≤ 0.

This inequality holds when a ∈ [-2, 0]. However, since we are in the case a < 0, the solution is a ∈ [-2, 0).

Therefore, for a ∈ [-2, 0), the union of the ranges is all real numbers. Therefore, for these values of a, the function f(x) intersects every horizontal line. However, the problem asks for the largest value of a. So, in the case of a < 0, the maximum a is approaching 0 from the left. However, in the case of a > 0, the maximum a is 2. Therefore, comparing 2 and 0, the largest value of a is 2. Therefore, the answer is 2?

Wait, but let me check if there's a possibility that for some a between 0 and 2, maybe there's a higher value? Wait, no. For a > 0, the maximum a is 2. For a < 0, the maximum a is approaching 0. Therefore, 2 is larger than 0. Therefore, the answer is 2. However, let me check if there's a mistake here.

Wait, but let me think again. For a < 0, the maximum a is approaching 0. But if a is approaching 0 from the negative side, then the function f(x) would be... Let me take a = -1, which is in [-2, 0). Let me check if the function covers all real numbers. For a = -1:

Linear part: x < -1, f(x) = -1*x + 2*(-1) = -x - 2. The range is (a² + 2a, ∞) = ((-1)^2 + 2*(-1), ∞) = (1 - 2, ∞) = (-1, ∞). The quadratic part: x ≥ -1, f(x) = -1*x². The range is (-∞, 0]. Therefore, the union is (-∞, 0] ∪ (-1, ∞) = (-∞, ∞). Therefore, yes, it covers all real numbers. Similarly, for a approaching 0 from the left, say a = -ε where ε is a small positive number. Then, the linear part's range is (a² + 2a, ∞) = (ε² - 2ε, ∞). Since ε is small, ε² - 2ε ≈ -2ε, which is approaching 0 from below. Therefore, the linear part's range is (-2ε, ∞), and the quadratic part's range is (-∞, 0]. Therefore, the union is (-∞, ∞). Therefore, for any a in [-2, 0), the function covers all real numbers. Therefore, the maximum a in this case is approaching 0. However, since we are to find the largest value of a, which is 2 in the positive case. Therefore, 2 is larger than 0, so the answer is 2.

But let me check if there's a case where a is between 0 and 2, but maybe for some reason, the function doesn't cover all real numbers? Wait, no. For a between 0 and 2, the union of the ranges is (-∞, a(a + 2)) ∪ [a³, ∞). Since a(a + 2) ≥ a³ (as we saw earlier for a ∈ (0, 2]), then the union is all real numbers. Therefore, for a between 0 and 2, the function covers all real numbers. Therefore, the maximum a is 2. Therefore, the answer is 2.

But let me check for a = 2, as before. For a = 2, the linear part is x < 2, f(x) = 2x + 4, which has range (-∞, 8). The quadratic part is x ≥ 2, f(x) = 2x², which has range [8, ∞). Therefore, union is all real numbers. Therefore, yes, a = 2 is acceptable.

But let me check if there's a case where even for a > 2, maybe the function still covers all real numbers? For example, suppose a = 3. Then, the linear part is x < 3, f(x) = 3x + 6, which has range (-∞, 15). The quadratic part is x ≥ 3, f(x) = 3x², which has range [27, ∞). Therefore, the union is (-∞, 15) ∪ [27, ∞). Therefore, there is a gap between 15 and 27. Therefore, horizontal lines between 15 and 27 are not intersected. Therefore, the function does not cover all real numbers. Therefore, a = 3 is invalid.

But what if a is negative? For example, a = -2. Let me check. For a = -2:

Linear part: x < -2, f(x) = -2x + 2*(-2) = -2x - 4. The range is (a² + 2a, ∞) = ((-2)^2 + 2*(-2), ∞) = (4 - 4, ∞) = (0, ∞). The quadratic part: x ≥ -2, f(x) = -2x². The range is (-∞, 0]. Therefore, the union is (-∞, 0] ∪ (0, ∞) = ℝ \ {0}. Wait, but there is a problem here. The union is (-∞, 0] ∪ (0, ∞), which is all real numbers except 0. Therefore, the horizontal line y = 0 is not intersected? Wait, but let me check if y = 0 is achieved.

For the quadratic part, f(x) = -2x². When is this equal to 0? When x² = 0, i.e., x = 0. Since x ≥ -2, x = 0 is in the domain. Therefore, f(0) = -2*(0)^2 = 0. Therefore, y = 0 is achieved at x = 0. Therefore, the union is actually (-∞, ∞). Wait, because (-∞, 0] includes 0, and (0, ∞) includes numbers greater than 0. Therefore, the union is (-∞, ∞). Therefore, for a = -2, the function covers all real numbers. Therefore, even though the linear part's range is (0, ∞) and the quadratic part's range is (-∞, 0], the union is all real numbers. Therefore, a = -2 is acceptable. However, for a = -2, which is less than 0, but the maximum a in the negative case is approaching 0. Therefore, the maximum a overall is 2.

But let me check for a = -2. The function f(x) is:

For x ≥ -2: f(x) = -2x².

For x < -2: f(x) = -2x - 4.

So, for example, if I want to solve f(x) = k for any k.

If k is in (-∞, 0], then there is a solution in the quadratic part (since the quadratic part covers (-∞, 0]).

If k is in (0, ∞), then there is a solution in the linear part (since the linear part covers (0, ∞)). Therefore, yes, all real numbers are covered. Therefore, a = -2 is acceptable. However, the problem asks for the largest value of a. Since a = 2 is larger than a = -2, the answer is 2.

But let me check if there is a value of a between 2 and something else? Wait, no. For a > 2, as we saw, there is a gap. Therefore, 2 is the maximum.

But let me think again. Is there a possibility that for some a > 2, even though there is a gap between a(a + 2) and a³, maybe the quadratic part can still cover that gap? Wait, no. Because for a > 0, the quadratic part is [a³, ∞), and the linear part is (-∞, a(a + 2)). Therefore, if a(a + 2) < a³, then the gap is between a(a + 2) and a³. Therefore, there is no way for the function to cover that gap. Therefore, the function cannot cover those values. Therefore, for a > 2, the function does not cover all real numbers. Therefore, 2 is indeed the maximum.

But let me check for a = 2, the gap is exactly at the point where the two ranges meet. For a = 2, the linear part goes up to 8, and the quadratic part starts at 8. Therefore, there is no gap. Therefore, the function covers all real numbers.

Therefore, the answer is 2. However, let me check if there's another case where maybe the function can cover all real numbers for some a > 2. Suppose someone says, maybe if the quadratic part can reach lower values? Wait, for a > 0, the quadratic part is ax² for x ≥ a. Since a > 0, ax² is increasing for x ≥ 0. Therefore, the minimum value of the quadratic part is at x = a, which is a³. Therefore, the quadratic part cannot go below a³. Therefore, if a³ is greater than a(a + 2), then there is a gap. Therefore, for a > 2, a³ > a(a + 2). Therefore, the quadratic part starts above the linear part's upper bound, creating a gap. Therefore, no way to cover that gap. Therefore, 2 is indeed the maximum.

But let me check for a = 1. For a = 1, which is less than 2. Then, linear part: x < 1, f(x) = x + 2. The range is (-∞, 1*(1) + 2) = (-∞, 3). The quadratic part: x ≥ 1, f(x) = x². The range is [1, ∞). Therefore, the union is (-∞, 3) ∪ [1, ∞) = (-∞, ∞). Therefore, yes, covers all real numbers. Therefore, for a = 1, it works. For a = 2, same thing. For a = 2.5, which is greater than 2, the linear part's upper bound is 2.5*(2.5 + 2) = 2.5*4.5 = 11.25. The quadratic part starts at (2.5)^3 = 15.625. Therefore, the gap between 11.25 and 15.625. Therefore, horizontal lines between 11.25 and 15.625 are not covered. Therefore, the function does not cover all real numbers. Therefore, a = 2 is the maximum.

But let me check if there's another way to approach this problem. Maybe by considering continuity or something else?

Wait, the function is piecewise defined. At x = a, the function has a value of f(a) = a*(a)^2 = a³ from the quadratic part, and from the linear part, approaching x = a from the left, the limit is a*a + 2a = a² + 2a. Therefore, for the function to be continuous at x = a, we need a³ = a² + 2a. Let me solve this equation:

a³ = a² + 2a

a³ - a² - 2a = 0

a(a² - a - 2) = 0

Therefore, a = 0 or a² - a - 2 = 0. The solutions to a² - a - 2 = 0 are a = [1 ± sqrt(1 + 8)] / 2 = [1 ± 3]/2, so a = 2 or a = -1. Therefore, the function is continuous at x = a when a = 0, 2, or -1. However, we already saw that a = 0 is not acceptable because the function becomes zero everywhere. However, for a = 2 or a = -1, the function is continuous at x = a. However, continuity at x = a is not necessary for the function to intersect every horizontal line. However, maybe the continuity is related to the coverage of the range?

But in our previous analysis, we saw that for a = 2, the function is continuous at x = a (since a³ = 8 and a² + 2a = 4 + 4 = 8). Therefore, the function is continuous at x = 2. However, for a = -1, the function is continuous at x = -1. Let me check for a = -1. For a = -1, the linear part approaches x = -1 from the left: f(x) approaches (-1)^2 + 2*(-1) = 1 - 2 = -1. The quadratic part at x = -1 is f(-1) = (-1)*(-1)^2 = -1. Therefore, continuous. However, for a = -1, the function covers all real numbers, as we saw earlier. However, the maximum a in the negative case is approaching 0, so 2 is still larger.

But maybe there's a different approach. Let me think. For the function to intersect every horizontal line, it must be that for any real number k, there exists an x such that f(x) = k. Therefore, for each k, there must be a solution to either ax² = k with x ≥ a or ax + 2a = k with x < a.

Let me consider solving these equations.

First, for the quadratic equation: ax² = k with x ≥ a. So, solving for x:

x = ±√(k/a). However, since x ≥ a, we need to check if √(k/a) ≥ a or -√(k/a) ≥ a. But this depends on the sign of a and the value of k.

Similarly, for the linear equation: ax + 2a = k => x = (k - 2a)/a = (k/a) - 2. And we need x < a. Therefore, (k/a) - 2 < a => k/a < a + 2 => k < a(a + 2) if a > 0, or k > a(a + 2) if a < 0. Wait, let me check:

From x < a:

(k/a) - 2 < a

Multiply both sides by a. However, the direction of inequality depends on the sign of a.

Case 1: a > 0.

Then, multiplying both sides by a (positive, so inequality direction remains):

k - 2a < a² => k < a² + 2a.

Case 2: a < 0.

Multiplying both sides by a (negative, so inequality direction reverses):

k - 2a > a² => k > a² + 2a.

Therefore, for the linear equation to have a solution x < a, we need:

If a > 0: k < a(a + 2)

If a < 0: k > a(a + 2)

Therefore, for the linear part to cover certain k's, depending on the sign of a.

Similarly, for the quadratic equation ax² = k with x ≥ a.

Let me analyze this.

First, solving ax² = k => x² = k/a. Therefore, real solutions exist only if k/a ≥ 0. Therefore, k and a must have the same sign.

Case 1: a > 0.

Then, k must be ≥ 0. Then, x = ±√(k/a). However, we need x ≥ a. Therefore, we need either √(k/a) ≥ a or -√(k/a) ≥ a. But since a > 0, -√(k/a) is negative, and since a > 0, -√(k/a) ≥ a would imply that a negative number is ≥ a positive number, which is impossible. Therefore, only √(k/a) ≥ a is possible. Therefore, √(k/a) ≥ a => k/a ≥ a² => k ≥ a³. Therefore, for a > 0, the quadratic equation has a solution x ≥ a if and only if k ≥ a³. Therefore, the quadratic part covers k ≥ a³.

Case 2: a < 0.

Then, k must be ≤ 0 (since k/a ≥ 0 and a < 0). Then, x² = k/a. Since k ≤ 0 and a < 0, k/a ≥ 0. Therefore, x = ±√(k/a). Now, we need x ≥ a. Since a < 0, and x can be positive or negative. Let me check:

If x = √(k/a), which is non-negative, then since a < 0, we need √(k/a) ≥ a. Since √(k/a) is non-negative and a is negative, this inequality is always true. Therefore, for any k ≤ 0, x = √(k/a) is a solution with x ≥ a (since x ≥ 0 ≥ a). Therefore, for a < 0, the quadratic equation ax² = k has a solution x ≥ a for any k ≤ 0. Additionally, the other solution x = -√(k/a) is negative. However, since a < 0, we need to check if -√(k/a) ≥ a. Let me see:

Let me denote t = -√(k/a). Since k ≤ 0 and a < 0, k/a ≥ 0, so t is real. Then, t = -√(k/a). Since √(k/a) ≥ 0, t ≤ 0. Therefore, t is negative or zero. Since a < 0, we need t ≥ a. Since t is negative and a is negative, this is equivalent to t ≥ a. However, since t = -√(k/a), which is a specific value. However, since we already have a solution x = √(k/a) ≥ a, the other solution x = -√(k/a) may or may not satisfy x ≥ a. However, since we only need at least one solution, the existence of x = √(k/a) is sufficient. Therefore, for a < 0, the quadratic equation covers all k ≤ 0.

Therefore, summarizing:

For a > 0:

- The linear part covers k < a(a + 2)
- The quadratic part covers k ≥ a³
Therefore, to cover all real numbers, we need that the union of (-∞, a(a + 2)) and [a³, ∞) is ℝ. Which requires that a(a + 2) ≥ a³, leading to a ∈ (0, 2].

For a < 0:

- The linear part covers k > a(a + 2)
- The quadratic part covers k ≤ 0
Therefore, the union is (-∞, 0] ∪ (a(a + 2), ∞). To cover all real numbers, we need that (a(a + 2), ∞) covers from some value less than or equal to 0 to infinity. Therefore, a(a + 2) ≤ 0, leading to a ∈ [-2, 0).

Therefore, combining both cases, the maximum value of a is 2.

Therefore, the answer is \boxed{2}.

**Final Answer**
\boxed{2}

To determine the **largest value of $ a $** such that the graph of the function
$$
f(x) =
\begin{cases}
ax^2 & \text{if } x \geq a,\\
ax + 2a & \text{if } x < a,
\end{cases}
$$
intersects **every horizontal line at least once**, we need to ensure that the function is **surjective** onto the real numbers $ \mathbb{R} $. That is, for **every real number $ k $**, there must exist at least one $ x $ such that $ f(x) = k $.

---

### Step 1: Analyze the Function's Behavior

We consider the function in two parts:

- **Quadratic part**: $ f(x) = ax^2 $ for $ x \geq a $
- **Linear part**: $ f(x) = ax + 2a $ for $ x < a $

We'll analyze the **range** of each part and then determine the **union of their ranges**.

---

### Step 2: Analyze the Quadratic Part

- For $ x \geq a $, the function is $ f(x) = ax^2 $
- If $ a > 0 $, this is a parabola opening upwards, and the minimum value occurs at $ x = a $, giving $ f(a) = a^3 $
- So, the range is $ [a^3, \infty) $

- If $ a < 0 $, the parabola opens downward, and the maximum value occurs at $ x = 0 $, giving $ f(0) = 0 $
- So, the range is $ (-\infty, 0] $

---

### Step 3: Analyze the Linear Part

- For $ x < a $, the function is $ f(x) = ax + 2a = a(x + 2) $
- If $ a > 0 $, the function is increasing, and as $ x \to -\infty $, $ f(x) \to -\infty $, and as $ x \to a^- $, $ f(x) \to a(a + 2) $
- So, the range is $ (-\infty, a(a + 2)) $

- If $ a < 0 $, the function is decreasing, and as $ x \to -\infty $, $ f(x) \to \infty $, and as $ x \to a^- $, $ f(x) \to a(a + 2) $
- So, the range is $ (a(a + 2), \infty) $

---

### Step 4: Determine When the Union of Ranges Covers $ \mathbb{R} $

We now consider the union of the two ranges:

- **Case 1: $ a > 0 $**
  - Quadratic part: $ [a^3, \infty) $
  - Linear part: $ (-\infty, a(a + 2)) $
  - Union: $ (-\infty, a(a + 2)) \cup [a^3, \infty) $

  For the union to be $ \mathbb{R} $, we must have:
  $$
  a(a + 2) \geq a^3
  $$
  Simplify:
  $$
  a^2 + 2a \geq a^3 \Rightarrow a^3 - a^2 - 2a \leq 0 \Rightarrow a(a^2 - a - 2) \leq 0
  $$
  Solve the inequality:
  $$
  a(a - 2)(a + 1) \leq 0
  $$
  The roots are $ a = 0, 2, -1 $. The inequality holds for:
  $$
  a \in [-1, 0] \cup [0, 2]
  $$
  Since we are considering $ a > 0 $, the valid interval is:
  $$
  a \in (0, 2]
  $$

- **Case 2: $ a < 0 $**
  - Quadratic part: $ (-\infty, 0] $
  - Linear part: $ (a(a + 2), \infty) $
  - Union: $ (-\infty, 0] \cup (a(a + 2), \infty) $

  For the union to be $ \mathbb{R} $, we must have:
  $$
  a(a + 2) \leq 0
  $$
  Solve:
  $$
  a(a + 2) \leq 0 \Rightarrow a \in [-2, 0]
  $$

---

### Step 5: Determine the Largest Value of $ a $

- From Case 1: $ a \in (0, 2] $
- From Case 2: $ a \in [-2, 0) $

The **largest value of $ a $** that satisfies the condition is:
$$
\boxed{2}
$$

This value ensures that the union of the ranges of the two parts of the function covers all real numbers, and thus the graph intersects every horizontal line at least once.

---

### Final Answer

$$
\boxed{2}
$$

Solution:
For $x < a,$ the graph of $y = f(x)$ is the same as the graph of $y = ax+2a,$ which is a line with slope $a$ and which passes through the point $(a, a^2+2a).$ For $x \ge a,$ the graph of $y = f(x)$ is the same as the graph of $y = ax^2,$ which is a parabola passing through the point $(a, a^3).$

Notice that the parabola only ever takes nonnegative values. Therefore, the line portion of the graph must have positive slope, because it must intersect horizontal lines which lie below the $x-$axis. Thus, $a > 0.$

For $a > 0,$ the line portion of the graph passes through all horizontal lines with height less than or equal to $a^2+2a,$ and the parabola portion of the graph passes through all horizontal lines with height greater than or equal to $a^3.$ Therefore, all horizontal lines are covered if and only if \[a^2 + 2a \ge a^3.\]Since $ a > 0,$ we can divide by $a$ to get \[a + 2 \ge a^2,\]so $0 \ge a^2 - a - 2 = (a-2) ( a+1).$ This means that $-1 \le a \le 2,$ so the greatest possible value of $a$ is $\boxed{2}.$

The graph of $y = f(x)$ for $a = 2$ is shown below (not to scale); note how the parabola and line meet at one point: [asy]
size(8cm);
import graph;

real a =2;
draw((-5,0)--(6,0),EndArrow());
draw((0,-6)--(0,14),EndArrow());

real g(real x) {return 0.5*a*(x-a)^2+a^3;}
real f(real x) {return a*x+2*a;}

draw(graph(f,-4.6,a),BeginArrow());
draw(graph(g,a,4.5),EndArrow());

label("$f(x)$",(0,15.5));
label("$x$",(6,0),E);
dot((2,8));
[/asy]