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, since we are talking about intersecting every horizontal line, that would mean that the range of f(x) must be all real numbers? Wait, no. Wait, if every horizontal line intersects the graph at least once, that would mean that the range of f(x) is all real numbers. Because if there's a horizontal line y = k that doesn't intersect the graph, then k is not in the range of f(x). Therefore, the condition is that the range of f(x) is all real numbers. Therefore, we need to find the largest 'a' such that f(x) is surjective onto ℝ.

But maybe I need to think more carefully. Let me check. Suppose that for every real number k, there exists an x such that f(x) = k. Therefore, the range of f(x) must be all real numbers. Therefore, the problem reduces to finding the largest 'a' such that the range of f(x) is ℝ.

Alternatively, maybe there's a different way to think about it. For example, if the function is continuous, then by the Intermediate Value Theorem, it would take all values between its minimum and maximum. But since we need it to intersect every horizontal line, the function must be surjective. However, if the function is not continuous, then maybe it can have different behaviors.

But first, let me check the continuity of f(x). The function is defined piecewise with two cases: ax² for x ≥ a, and ax + 2a for x < a. Let me check if there's a point where the function might not be continuous. The point where the definition changes is at x = a. Let me compute the left-hand limit and the right-hand limit at x = a.

Left-hand limit as x approaches a from the left: lim_{x→a⁻} f(x) = a*a + 2a = a² + 2a.

Right-hand limit as x approaches a from the right: lim_{x→a⁺} f(x) = a*(a)² = a³.

Therefore, for continuity at x = a, we need a² + 2a = a³. Let me solve that equation:

a³ - a² - 2a = 0

Factor out an a:

a(a² - a - 2) = 0

Which factors further:

a(a - 2)(a + 1) = 0

Therefore, the solutions are a = 0, a = 2, a = -1.

So, if a is 0, 2, or -1, then the function is continuous at x = a. However, the problem doesn't specify that the function needs to be continuous. It just says that the graph of y = f(x) intersects every horizontal line at least once. Therefore, even if there's a discontinuity at x = a, as long as the function covers all real numbers, it's okay. However, if there's a discontinuity, we need to make sure that the function still covers all real numbers.

But maybe the problem is designed such that the function is continuous? Wait, but the problem says "the graph of y = f(x) intersects every horizontal line at least once". So, even if there's a jump discontinuity, as long as the function's range is all real numbers, it's okay.

But perhaps the key is to analyze the range of f(x) depending on the value of 'a'. Let me try to analyze the function's range.

First, let's consider the two pieces of the function:

1. For x ≥ a: f(x) = ax². This is a quadratic function. Depending on the sign of 'a', this parabola opens upwards or downwards.

2. For x < a: f(x) = ax + 2a. This is a linear function with slope 'a'.

So, the range of f(x) will be the union of the ranges of these two pieces. Therefore, to have the entire real line covered, the union of these two ranges must be all real numbers.

But let's think about how each piece contributes to the range.

First, for the linear part: f(x) = ax + 2a for x < a. Let me denote this as f1(x) = a(x + 2). So, this is a linear function with slope 'a'. The domain of this piece is x < a. Therefore, the range of this linear function depends on the slope 'a'.

Similarly, for the quadratic part: f(x) = ax² for x ≥ a. The domain here is x ≥ a, so depending on the value of 'a', the quadratic can have different behaviors.

So, let's analyze each part.

First, the linear part: f1(x) = a(x + 2) for x < a. Let me think about the range of this function. Since x can be any real number less than a, the range of f1(x) depends on the slope 'a'.

Case 1: If a > 0. Then, as x approaches negative infinity, f1(x) approaches negative infinity, and as x approaches a from the left, f1(x) approaches a(a + 2). Therefore, the range of f1(x) is (-∞, a(a + 2)).

Case 2: If a < 0. Then, as x approaches negative infinity, f1(x) approaches positive infinity (since a is negative and x is going to negative infinity, so multiplying gives positive infinity). As x approaches a from the left, f1(x) approaches a(a + 2). Therefore, the range of f1(x) is (a(a + 2), ∞).

Case 3: If a = 0. Then f1(x) = 0*(x + 2) = 0 for all x < 0. Therefore, the range is just {0}.

Now, for the quadratic part: f2(x) = ax² for x ≥ a. Let's analyze this.

Again, depending on the sign of 'a', the quadratic will open upwards or downwards.

Case 1: If a > 0. Then, the parabola opens upwards. The minimum value of f2(x) occurs at x = 0 if the vertex is within the domain x ≥ a. Wait, but the vertex of ax² is at x = 0. However, the domain here is x ≥ a. Therefore, if a > 0, then the domain x ≥ a is to the right of the vertex. Therefore, the function f2(x) = ax² is increasing on x ≥ a because the parabola opens upwards and the vertex is at x = 0. Therefore, the minimum value of f2(x) on x ≥ a is at x = a, which is f2(a) = a*(a)^2 = a³. As x approaches infinity, f2(x) approaches infinity. Therefore, the range of f2(x) is [a³, ∞).

Case 2: If a < 0. Then, the parabola opens downward. The vertex is at x = 0. However, the domain is x ≥ a. Since a is negative, the domain includes x from a (which is negative) up to infinity. However, since the parabola opens downward, the maximum value occurs at the vertex x = 0 if 0 is in the domain. But since a < 0, 0 is in the domain (since x ≥ a and a < 0). Therefore, the maximum value of f2(x) is at x = 0, which is f2(0) = a*(0)^2 = 0. Then, as x moves away from 0 towards infinity, the function decreases. However, since the domain is x ≥ a, which includes x approaching negative infinity? Wait, no. Wait, the domain is x ≥ a. If a is negative, then x can be from a (negative) up to infinity. However, the function f2(x) = ax² is a downward opening parabola. Therefore, on the interval x ≥ a, which includes x from a (negative) to infinity, the function will have a maximum at x = 0 (if 0 is in the domain) and then decrease towards negative infinity as x approaches infinity? Wait, no. Wait, if a is negative, then for x ≥ a, as x increases, ax² will decrease because the parabola opens downward. Wait, but when x is large positive, ax² is negative because a is negative. However, when x is approaching negative infinity, but since the domain is x ≥ a (which is negative), x can't go to negative infinity. The domain is x ≥ a, so the minimum x is a. Therefore, for x ≥ a, when a is negative, the function f2(x) = ax² will have its maximum at x = 0 (if 0 ≥ a, which it is, since a is negative) and then decrease as x moves away from 0 in both directions. However, since x ≥ a, and a is negative, when x is between a and 0, moving towards 0, the function increases to the maximum at x = 0, and then decreases as x moves beyond 0 to infinity. Therefore, the range of f2(x) when a < 0 is (-∞, 0]. Wait, but let me check:

At x = a, f2(a) = a*(a)^2 = a³. Since a is negative, a³ is negative. As x approaches 0 from the left, f2(x) approaches 0. Then, as x increases beyond 0, f2(x) decreases from 0 to negative infinity as x approaches infinity. Therefore, the range of f2(x) when a < 0 is (-∞, 0]. Wait, but also, when x is between a and 0, the function goes from a³ (which is negative) up to 0. So the entire range is from -∞ up to 0? Wait, but when x is between a and 0, the function increases from a³ to 0, and when x is greater than 0, it decreases from 0 to -∞. Therefore, the range is (-∞, 0]. So yes, the range of f2(x) when a < 0 is (-∞, 0].

Case 3: If a = 0. Then f2(x) = 0*x² = 0 for x ≥ 0. Therefore, the range is {0}.

So, summarizing:

For the quadratic part f2(x):

- If a > 0: range is [a³, ∞)
- If a < 0: range is (-∞, 0]
- If a = 0: range is {0}

For the linear part f1(x):

- If a > 0: range is (-∞, a(a + 2))
- If a < 0: range is (a(a + 2), ∞)
- If a = 0: range is {0}

Therefore, the total range of f(x) is the union of the ranges of f1(x) and f2(x). So, to have the entire real line covered, the union of these two ranges must be ℝ. Let's analyze for different cases of a.

First, let's consider a > 0. Then:

- f1(x) has range (-∞, a(a + 2))
- f2(x) 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 upper bound of the first interval and the lower bound of the second interval overlap or meet. That is, we need that a(a + 2) ≥ a³. Because if a(a + 2) ≥ a³, then the two intervals overlap or meet, so their union is (-∞, ∞). Wait, but if a(a + 2) ≥ a³, then the upper bound of the first interval is greater than or equal to the lower bound of the second interval. Therefore, the union would be (-∞, ∞). 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 a > 0, the condition is a(a + 2) ≥ a³. Let's solve this inequality:

a(a + 2) ≥ a³

Subtract a³ from both sides:

a(a + 2) - a³ ≥ 0

Simplify:

a² + 2a - a³ ≥ 0

Rearranged:

- a³ + a² + 2a ≥ 0

Multiply both sides by -1 (which reverses the inequality):

a³ - a² - 2a ≤ 0

Factor:

a(a² - a - 2) ≤ 0

Which factors further:

a(a - 2)(a + 1) ≤ 0

So, we have the inequality a(a - 2)(a + 1) ≤ 0. Let's find the intervals where this holds.

First, find the critical points: a = -1, 0, 2.

We can make a sign chart:

Intervals:

1. a < -1
2. -1 < a < 0
3. 0 < a < 2
4. a > 2

Test each interval:

1. a < -1: Let's pick a = -2. Then (-2)(-2 - 2)(-2 + 1) = (-2)(-4)(-1) = (-2)(4) = -8 < 0. So the inequality holds here.

2. -1 < a < 0: Let's pick a = -0.5. Then (-0.5)(-0.5 - 2)(-0.5 + 1) = (-0.5)(-2.5)(0.5) = (-0.5)(-1.25) = 0.625 > 0. So the inequality does not hold here.

3. 0 < a < 2: Let's pick a = 1. Then (1)(1 - 2)(1 + 1) = (1)(-1)(2) = -2 < 0. So the inequality holds here.

4. a > 2: Let's pick a = 3. Then (3)(3 - 2)(3 + 1) = 3*1*4 = 12 > 0. So the inequality does not hold here.

Additionally, check the critical points:

At a = -1: (-1)(-1 - 2)(-1 + 1) = (-1)(-3)(0) = 0. So equality holds.

At a = 0: 0*(...)=0. Equality holds.

At a = 2: 2*(0)*(3) = 0. Equality holds.

Therefore, the inequality a(a - 2)(a + 1) ≤ 0 holds for a ∈ (-∞, -1] ∪ [0, 2].

But remember, we were considering the case where a > 0. Therefore, in this case, the inequality holds for a ∈ (0, 2]. Therefore, for a > 0, the condition that the union of the ranges is ℝ is satisfied when a ∈ (0, 2].

But we need to check if at a = 2, the union is indeed ℝ. Let's check:

At a = 2:

For f1(x): range is (-∞, 2*(2 + 2)) = (-∞, 8)

For f2(x): range is [2³, ∞) = [8, ∞)

Therefore, the union is (-∞, 8) ∪ [8, ∞) = ℝ. Perfect, so there's no gap. Therefore, for a in (0, 2], the union of the ranges is ℝ. Therefore, for a > 0, the maximum value of a is 2.

But we need to check other cases as well. Let's check for a < 0.

Case 2: a < 0.

For a < 0:

- f1(x) has range (a(a + 2), ∞)
- f2(x) has range (-∞, 0]

Therefore, the union of these two ranges is (-∞, 0] ∪ (a(a + 2), ∞). For this union to be all real numbers, we need that the upper bound of the first interval (which is 0) and the lower bound of the second interval (which is a(a + 2)) overlap or meet. That is, we need that a(a + 2) ≤ 0. Because if a(a + 2) ≤ 0, then the second interval starts at a(a + 2) which is ≤ 0, and since the first interval goes up to 0, the union would be (-∞, ∞). Wait, let me think again.

Wait, the first interval is (-∞, 0], and the second interval is (a(a + 2), ∞). For their union to be all real numbers, we need that the second interval starts at a(a + 2) ≤ 0, so that (a(a + 2), ∞) includes all numbers greater than a(a + 2). But since the first interval already covers up to 0, if a(a + 2) ≤ 0, then the second interval starts at some value ≤ 0, so the union would be (-∞, ∞). Wait, but if a(a + 2) is less than 0, then (a(a + 2), ∞) includes all numbers greater than a(a + 2), which includes numbers from a(a + 2) to ∞. Since the first interval is (-∞, 0], then the union would be (-∞, ∞) if a(a + 2) ≤ 0. Because if a(a + 2) ≤ 0, then (a(a + 2), ∞) includes all numbers greater than a(a + 2), which includes numbers from a(a + 2) to ∞. Since the first interval covers up to 0, and the second interval covers from a(a + 2) to ∞, then if a(a + 2) ≤ 0, then the union is (-∞, ∞). However, if a(a + 2) > 0, then there is a gap between 0 and a(a + 2). Therefore, the condition is a(a + 2) ≤ 0.

So, solving a(a + 2) ≤ 0 for a < 0.

Let me solve the inequality a(a + 2) ≤ 0.

The critical points are a = -2 and a = 0. Since we are considering a < 0, the interval is a ∈ (-∞, 0). The inequality a(a + 2) ≤ 0 holds when a ∈ [-2, 0]. Therefore, for a < 0, the inequality holds when a ∈ [-2, 0). Therefore, for a ∈ [-2, 0), the union of the ranges is ℝ. Therefore, for a < 0, the maximum value of a is approaching 0 from the left, but since we are looking for the largest value of a overall, which could be in the positive case (a=2) or in the negative case (a approaching 0). Since 2 is larger than 0, the maximum a is 2. However, we need to check if there are other cases.

Case 3: a = 0. Then, both f1(x) and f2(x) have range {0}. Therefore, the total range is {0}, which is not all real numbers. Therefore, a = 0 is invalid.

Therefore, so far, for a > 0, the maximum a is 2, and for a < 0, the maximum a is approaching 0. Therefore, the overall maximum a is 2. However, we need to check if there are any other constraints or if there's a case where even though the union of ranges is ℝ, there's some other issue. Wait, but the problem says "the graph of y = f(x) intersects every horizontal line at least once". So, if the range is ℝ, then every horizontal line y = k intersects the graph at least once. Therefore, if the range is ℝ, then the condition is satisfied. Therefore, for a ∈ (0, 2], the range is ℝ, so the condition is satisfied. For a < -2, the range is not ℝ. For a between -2 and 0, the range is ℝ. Therefore, the maximum value of a is 2. However, let me check for a = -2. Let me check if a = -2 is allowed.

For a = -2:

First, check the ranges.

For f1(x) = ax + 2a = -2x + 2*(-2) = -2x - 4. The domain is x < a = -2. Therefore, the range of f1(x) is (a(a + 2), ∞) = (-2*(-2 + 2), ∞) = (-2*(0), ∞) = (0, ∞). Wait, but earlier I thought that for a < 0, the range of f1(x) is (a(a + 2), ∞). Let me check that again.

Wait, for a < 0, f1(x) = ax + 2a = a(x + 2). The domain is x < a. So, as x approaches negative infinity, since a is negative, ax + 2a approaches positive infinity. As x approaches a from the left, f1(x) approaches a(a + 2). Therefore, the range is (a(a + 2), ∞). For a = -2, that would be (-2*(-2 + 2), ∞) = (-2*(0), ∞) = (0, ∞).

For f2(x) = ax² = -2x² for x ≥ a = -2. The domain is x ≥ -2. Since a = -2 < 0, the parabola opens downward. The maximum value is at x = 0, which is 0. As x approaches infinity, f2(x) approaches negative infinity. Therefore, the range of f2(x) is (-∞, 0]. Therefore, the union of (0, ∞) and (-∞, 0] is ℝ. Therefore, for a = -2, the range is ℝ. Therefore, a = -2 is allowed. However, since we are looking for the largest value of a, which is 2, which is larger than -2, so 2 is still the maximum.

But let me check if there's a case where even though the union of ranges is ℝ, there's a problem with the function not intersecting some horizontal line. Wait, but if the range is ℝ, then every horizontal line y = k intersects the graph. Therefore, the condition is satisfied. Therefore, the maximum a is 2. However, let me check for a = 2, whether the function actually meets every horizontal line.

For a = 2:

f(x) is:

- 2x² for x ≥ 2

- 2x + 4 for x < 2

So, for the linear part, x < 2, f(x) = 2x + 4. The range of this part is (-∞, 2*2 + 4) = (-∞, 8). For the quadratic part, x ≥ 2, f(x) = 2x², which has range [2*(2)^2, ∞) = [8, ∞). Therefore, the union is (-∞, 8) ∪ [8, ∞) = ℝ. Therefore, every horizontal line intersects the graph.

But let me check for a value of k = 8. The horizontal line y = 8 intersects the graph at x = 2 (from the quadratic part) and also, does it intersect the linear part? Let's see. For the linear part, solving 2x + 4 = 8 gives x = 2. But x = 2 is not in the domain of the linear part (x < 2). Therefore, the only intersection is at x = 2 from the quadratic part. Therefore, even though the ranges meet at 8, the function is continuous at x = 2? Wait, earlier when we checked continuity, for a = 2, the left-hand limit is a² + 2a = 4 + 4 = 8, and the right-hand limit is a³ = 8. Therefore, the function is continuous at x = 2. Therefore, the point x = 2 is included in the quadratic part, so y = 8 is achieved at x = 2. Therefore, the horizontal line y = 8 intersects the graph at x = 2. Therefore, it's okay.

But what if a was slightly less than 2? Let's say a = 1.9. Then, the linear part would have range (-∞, 1.9*(1.9 + 2)) = (-∞, 1.9*3.9) ≈ (-∞, 7.41). The quadratic part would have range [a³, ∞) ≈ [6.859, ∞). Therefore, the union is (-∞, 7.41) ∪ [6.859, ∞) = (-∞, ∞). Therefore, there is an overlap between 6.859 and 7.41, so the union is ℝ. Therefore, even for a < 2, the union is ℝ. However, when a = 2, the two ranges meet exactly at 8, so there's no gap. Therefore, a = 2 is acceptable.

But let me check if there's a case where even though the union of ranges is ℝ, there's a horizontal line that doesn't intersect the graph. Wait, but if the union of the ranges is ℝ, then for any k ∈ ℝ, there exists some x such that f(x) = k. Therefore, the horizontal line y = k intersects the graph. Therefore, the condition is satisfied. Therefore, the maximum value of a is 2.

But let me check for a = 2, if there's any horizontal line that doesn't intersect. For example, take k = 7.5. Since the linear part goes up to 8, and the quadratic part starts at 8. So, 7.5 is between 6.859 and 8. Wait, for a = 2, the quadratic part starts at 8. So, the linear part goes up to 8, and the quadratic part starts at 8. Therefore, the value 7.5 is between the upper bound of the linear part (which is 8) and the lower bound of the quadratic part (which is 8). Wait, but if the linear part approaches 8 as x approaches 2 from the left, and the quadratic part starts at 8 when x = 2, then the value 7.5 is less than 8. Therefore, 7.5 is in the range of the linear part. Wait, the linear part's range is (-∞, 8). Therefore, 7.5 is in that range. Therefore, there exists an x < 2 such that 2x + 4 = 7.5. Solving: 2x + 4 = 7.5 => 2x = 3.5 => x = 1.75, which is less than 2. Therefore, it's valid. Similarly, for k = 8, as discussed, it's achieved at x = 2. For k = 9, it's achieved by the quadratic part. For k = -5, it's achieved by the linear part. Therefore, all horizontal lines are covered. Therefore, a = 2 is valid.

But let me check if there's a case where even though the union of ranges is ℝ, the function might not actually reach certain values. For example, suppose that the two pieces don't actually meet at the overlapping point. Wait, but in the case of a = 2, they meet at 8. For a < 2, the upper bound of the linear part is less than the lower bound of the quadratic part? Wait, no. Wait, for a < 2, the upper bound of the linear part is a(a + 2), and the lower bound of the quadratic part is a³. So, for a in (0, 2), we have a(a + 2) ≥ a³, so the upper bound of the linear part is greater than or equal to the lower bound of the quadratic part. Therefore, the union is ℝ. Therefore, there is no gap. Therefore, for a in (0, 2], the union is ℝ. Therefore, the maximum a is 2.

But let me check for a = 1. Let's take a = 1. Then:

Linear part: range is (-∞, 1*(1 + 2)) = (-∞, 3)

Quadratic part: range is [1³, ∞) = [1, ∞)

Therefore, union is (-∞, 3) ∪ [1, ∞) = ℝ. Therefore, yes, it works. For example, k = 2 is in both ranges. For k = 0, it's in the linear part. For k = 4, it's in the quadratic part. So, all horizontal lines are covered.

But let me check for a = 2. Suppose someone says, "Wait, what about the value k = 8? It's achieved at x = 2. But what if there's a horizontal line that is tangent to the graph or something?" But no, the problem just requires that every horizontal line intersects the graph at least once. It doesn't require that they intersect exactly once or anything else. So, even if a horizontal line is tangent, it still intersects once. Therefore, it's okay.

But let me think again. Suppose that for some a, the function is not surjective. For example, if a is too small. For example, if a = 1/2. Then, the linear part has range (-∞, (1/2)(1/2 + 2)) = (-∞, (1/2)(5/2)) = (-∞, 5/4). The quadratic part has range [ (1/2)^3, ∞ ) = [1/8, ∞). Therefore, the union is (-∞, 5/4) ∪ [1/8, ∞) = ℝ. Therefore, even though there is an overlap between 1/8 and 5/4, the union is ℝ. Therefore, it's okay.

But if a is less than 0, say a = -1. Then:

For a = -1:

Linear part: range is (a(a + 2), ∞) = (-1*(-1 + 2), ∞) = (-1*(1), ∞) = (-1, ∞)

Quadratic part: range is (-∞, 0]

Therefore, union is (-∞, 0] ∪ (-1, ∞) = ℝ. Therefore, it's okay. For example, k = -0.5 is in the quadratic part, k = 0.5 is in the linear part, etc.

But if a = -3:

For a = -3:

Linear part: range is (a(a + 2), ∞) = (-3*(-3 + 2), ∞) = (-3*(-1), ∞) = (3, ∞)

Quadratic part: range is (-∞, 0]

Therefore, union is (-∞, 0] ∪ (3, ∞). Therefore, there is a gap between 0 and 3. Therefore, horizontal lines between 0 and 3 do not intersect the graph. Therefore, a = -3 is invalid. Therefore, for a < -2, the union is not ℝ. Therefore, the condition is only satisfied for a ∈ [-2, 0) ∪ (0, 2]. But since we are looking for the largest a, which is 2.

But let me check for a = -2. As before, for a = -2:

Linear part: range is (a(a + 2), ∞) = (-2*(0), ∞) = (0, ∞)

Quadratic part: range is (-∞, 0]

Therefore, union is (-∞, 0] ∪ (0, ∞) = ℝ. Therefore, it's okay. Therefore, a = -2 is valid. However, since we are looking for the largest a, which is 2, which is greater than -2, so 2 is still the maximum.

But let me check if there's a case where even for a between -2 and 0, there's some problem. For example, take a = -1. Then, as above, the union is ℝ. Therefore, it's okay. Therefore, the maximum a is 2.

But let me check if there's a case where even though the union of ranges is ℝ, the function might not actually achieve some values. For example, suppose that the two pieces don't actually cover the entire range. Wait, but we already considered the ranges. For example, for a > 0, the linear part covers (-∞, a(a + 2)) and the quadratic part covers [a³, ∞). If a(a + 2) ≥ a³, then the union is ℝ. Therefore, for any k in ℝ, if k ≤ a(a + 2), then it's covered by the linear part, and if k ≥ a³, it's covered by the quadratic part. Since a(a + 2) ≥ a³, then for k between a³ and a(a + 2), it's covered by both. Therefore, there's no problem. Therefore, the function is surjective.

Therefore, the conclusion is that the largest value of a is 2.

But let me check if there's a possibility that for a > 2, the function does not cover all real numbers. For example, take a = 3. Then:

Linear part: range is (-∞, 3*(3 + 2)) = (-∞, 15)

Quadratic part: range is [3³, ∞) = [27, ∞)

Therefore, the union is (-∞, 15) ∪ [27, ∞). Therefore, there is a gap between 15 and 27. Therefore, horizontal lines between 15 and 27 do not intersect the graph. Therefore, a = 3 is invalid. Therefore, for a > 2, the function does not cover all real numbers. Therefore, the maximum a is indeed 2.

Therefore, the answer is 2. However, let me check once again for a = 2, if there's any possible horizontal line that doesn't intersect. For example, take k = 8. As discussed, it's achieved at x = 2. For k = 7.5, achieved by the linear part. For k = 9, achieved by the quadratic part. For k = -10, achieved by the linear part. Therefore, all horizontal lines are covered. Therefore, a = 2 is valid.

Therefore, the largest value of a is 2.

**Final Answer**
The largest value of $ a $ is $\boxed{2}$.

To determine the **largest value of $ a $** such that the graph of the piecewise 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 must ensure that the **range of $ f(x) $** is the entire set of real numbers $ \mathbb{R} $.

---

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

The function is defined in two parts:

- **For $ x \geq a $:** $ f(x) = ax^2 $, a quadratic function.
- **For $ x < a $:** $ f(x) = ax + 2a $, a linear function.

We'll analyze the **range** of each piece and then consider their **union** to determine when the total range is $ \mathbb{R} $.

---

### Step 2: Determine the Range of Each Piece

#### **Case 1: $ a > 0 $**

- **Quadratic part:** $ f(x) = ax^2 $ for $ x \geq a $.
  - Since $ a > 0 $, the parabola opens upwards.
  - The minimum value occurs at $ x = a $: $ f(a) = a^3 $.
  - As $ x \to \infty $, $ f(x) \to \infty $.
  - So, the range is $ [a^3, \infty) $.

- **Linear part:** $ f(x) = ax + 2a $ for $ x < a $.
  - As $ x \to -\infty $, $ f(x) \to -\infty $.
  - As $ x \to a^- $, $ f(x) \to a(a + 2) $.
  - So, the range is $ (-\infty, a(a + 2)) $.

- **Union of ranges:**
  $$
  (-\infty, a(a + 2)) \cup [a^3, \infty)
  $$
  For this 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
  $$
  Factor:
  $$
  a(a^2 - a - 2) \leq 0 \Rightarrow a(a - 2)(a + 1) \leq 0
  $$

  The critical points are $ a = -1, 0, 2 $.
  The inequality holds for:
  $$
  a \in (-\infty, -1] \cup [0, 2]
  $$

  Since we are considering $ a > 0 $, the valid interval is:
  $$
  a \in (0, 2]
  $$

  So, for $ a \in (0, 2] $, the union of the ranges is $ \mathbb{R} $, and the function intersects every horizontal line.

---

#### **Case 2: $ a < 0 $**

- **Quadratic part:** $ f(x) = ax^2 $ for $ x \geq a $.
  - Since $ a < 0 $, the parabola opens downward.
  - The maximum value occurs at $ x = 0 $: $ f(0) = 0 $.
  - As $ x \to \infty $, $ f(x) \to -\infty $.
  - So, the range is $ (-\infty, 0] $.

- **Linear part:** $ f(x) = ax + 2a $ for $ x < a $.
  - As $ x \to -\infty $, $ f(x) \to \infty $.
  - As $ x \to a^- $, $ f(x) \to a(a + 2) $.
  - So, the range is $ (a(a + 2), \infty) $.

- **Union of ranges:**
  $$
  (-\infty, 0] \cup (a(a + 2), \infty)
  $$
  For this to be $ \mathbb{R} $, we must have:
  $$
  a(a + 2) \leq 0
  $$
  Solve:
  $$
  a(a + 2) \leq 0 \Rightarrow a \in [-2, 0]
  $$

  So, for $ a \in [-2, 0] $, the union of the ranges is $ \mathbb{R} $, and the function intersects every horizontal line.

---

#### **Case 3: $ a = 0 $**

- Both pieces become constant:
  - $ f(x) = 0 $ for all $ x $.
  - So, the range is $ \{0\} $, which is not $ \mathbb{R} $.

---

### Step 3: Determine the Largest Valid $ a $

From the above:

- For $ a \in (0, 2] $, the function intersects every horizontal line.
- For $ a \in [-2, 0] $, the function also intersects every horizontal line.
- But since we are asked for the **largest** value of $ a $, the maximum is:
  $$
  \boxed{2}
  $$

---

### 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, since we are talking about intersecting every horizontal line, that would mean that the range of f(x) must be all real numbers? Wait, no. Wait, if every horizontal line intersects the graph at least once, that would mean that the range of f(x) is all real numbers. Because if there's a horizontal line y = k that doesn't intersect the graph, then k is not in the range of f(x). Therefore, the condition is that the range of f(x) is all real numbers. Therefore, we need to find the largest 'a' such that f(x) is surjective onto ℝ.

But maybe I need to think more carefully. Let me check. Suppose that for every real number k, there exists an x such that f(x) = k. Therefore, the range of f(x) must be all real numbers. Therefore, the problem reduces to finding the largest 'a' such that the range of f(x) is ℝ.

Alternatively, maybe there's a different way to think about it. For example, if the function is continuous, then by the Intermediate Value Theorem, it would take all values between its minimum and maximum. But since we need it to intersect every horizontal line, the function must be surjective. However, if the function is not continuous, then maybe it can have different behaviors.

But first, let me check the continuity of f(x). The function is defined piecewise with two cases: ax² for x ≥ a, and ax + 2a for x < a. Let me check if there's a point where the function might not be continuous. The point where the definition changes is at x = a. Let me compute the left-hand limit and the right-hand limit at x = a.

Left-hand limit as x approaches a from the left: lim_{x→a⁻} f(x) = a*a + 2a = a² + 2a.

Right-hand limit as x approaches a from the right: lim_{x→a⁺} f(x) = a*(a)² = a³.

Therefore, for continuity at x = a, we need a² + 2a = a³. Let me solve that equation:

a³ - a² - 2a = 0

Factor out an a:

a(a² - a - 2) = 0

Which factors further:

a(a - 2)(a + 1) = 0

Therefore, the solutions are a = 0, a = 2, a = -1.

So, if a is 0, 2, or -1, then the function is continuous at x = a. However, the problem doesn't specify that the function needs to be continuous. It just says that the graph of y = f(x) intersects every horizontal line at least once. Therefore, even if there's a discontinuity at x = a, as long as the function covers all real numbers, it's okay. However, if there's a discontinuity, we need to make sure that the function still covers all real numbers.

But maybe the problem is designed such that the function is continuous? Wait, but the problem says "the graph of y = f(x) intersects every horizontal line at least once". So, even if there's a jump discontinuity, as long as the function's range is all real numbers, it's okay.

But perhaps the key is to analyze the range of f(x) depending on the value of 'a'. Let me try to analyze the function's range.

First, let's consider the two pieces of the function:

1. For x ≥ a: f(x) = ax². This is a quadratic function. Depending on the sign of 'a', this parabola opens upwards or downwards.

2. For x < a: f(x) = ax + 2a. This is a linear function with slope 'a'.

So, the range of f(x) will be the union of the ranges of these two pieces. Therefore, to have the entire real line covered, the union of these two ranges must be all real numbers.

But let's think about how each piece contributes to the range.

First, for the linear part: f(x) = ax + 2a for x < a. Let me denote this as f1(x) = a(x + 2). So, this is a linear function with slope 'a'. The domain of this piece is x < a. Therefore, the range of this linear function depends on the slope 'a'.

Similarly, for the quadratic part: f(x) = ax² for x ≥ a. The domain here is x ≥ a, so depending on the value of 'a', the quadratic can have different behaviors.

So, let's analyze each part.

First, the linear part: f1(x) = a(x + 2) for x < a. Let me think about the range of this function. Since x can be any real number less than a, the range of f1(x) depends on the slope 'a'.

Case 1: If a > 0. Then, as x approaches negative infinity, f1(x) approaches negative infinity, and as x approaches a from the left, f1(x) approaches a(a + 2). Therefore, the range of f1(x) is (-∞, a(a + 2)).

Case 2: If a < 0. Then, as x approaches negative infinity, f1(x) approaches positive infinity (since a is negative and x is going to negative infinity, so multiplying gives positive infinity). As x approaches a from the left, f1(x) approaches a(a + 2). Therefore, the range of f1(x) is (a(a + 2), ∞).

Case 3: If a = 0. Then f1(x) = 0*(x + 2) = 0 for all x < 0. Therefore, the range is just {0}.

Now, for the quadratic part: f2(x) = ax² for x ≥ a. Let's analyze this.

Again, depending on the sign of 'a', the quadratic will open upwards or downwards.

Case 1: If a > 0. Then, the parabola opens upwards. The minimum value of f2(x) occurs at x = 0 if the vertex is within the domain x ≥ a. Wait, but the vertex of ax² is at x = 0. However, the domain here is x ≥ a. Therefore, if a > 0, then the domain x ≥ a is to the right of the vertex. Therefore, the function f2(x) = ax² is increasing on x ≥ a because the parabola opens upwards and the vertex is at x = 0. Therefore, the minimum value of f2(x) on x ≥ a is at x = a, which is f2(a) = a*(a)^2 = a³. As x approaches infinity, f2(x) approaches infinity. Therefore, the range of f2(x) is [a³, ∞).

Case 2: If a < 0. Then, the parabola opens downward. The vertex is at x = 0. However, the domain is x ≥ a. Since a is negative, the domain includes x from a (which is negative) up to infinity. However, since the parabola opens downward, the maximum value occurs at the vertex x = 0 if 0 is in the domain. But since a < 0, 0 is in the domain (since x ≥ a and a < 0). Therefore, the maximum value of f2(x) is at x = 0, which is f2(0) = a*(0)^2 = 0. Then, as x moves away from 0 towards infinity, the function decreases. However, since the domain is x ≥ a, which includes x approaching negative infinity? Wait, no. Wait, the domain is x ≥ a. If a is negative, then x can be from a (negative) up to infinity. However, the function f2(x) = ax² is a downward opening parabola. Therefore, on the interval x ≥ a, which includes x from a (negative) to infinity, the function will have a maximum at x = 0 (if 0 is in the domain) and then decrease towards negative infinity as x approaches infinity? Wait, no. Wait, if a is negative, then for x ≥ a, as x increases, ax² will decrease because the parabola opens downward. Wait, but when x is large positive, ax² is negative because a is negative. However, when x is approaching negative infinity, but since the domain is x ≥ a (which is negative), x can't go to negative infinity. The domain is x ≥ a, so the minimum x is a. Therefore, for x ≥ a, when a is negative, the function f2(x) = ax² will have its maximum at x = 0 (if 0 ≥ a, which it is, since a is negative) and then decrease as x moves away from 0 in both directions. However, since x ≥ a, and a is negative, when x is between a and 0, moving towards 0, the function increases to the maximum at x = 0, and then decreases as x moves beyond 0 to infinity. Therefore, the range of f2(x) when a < 0 is (-∞, 0]. Wait, but let me check:

At x = a, f2(a) = a*(a)^2 = a³. Since a is negative, a³ is negative. As x approaches 0 from the left, f2(x) approaches 0. Then, as x increases beyond 0, f2(x) decreases from 0 to negative infinity as x approaches infinity. Therefore, the range of f2(x) when a < 0 is (-∞, 0]. Wait, but also, when x is between a and 0, the function goes from a³ (which is negative) up to 0. So the entire range is from -∞ up to 0? Wait, but when x is between a and 0, the function increases from a³ to 0, and when x is greater than 0, it decreases from 0 to -∞. Therefore, the range is (-∞, 0]. So yes, the range of f2(x) when a < 0 is (-∞, 0].

Case 3: If a = 0. Then f2(x) = 0*x² = 0 for x ≥ 0. Therefore, the range is {0}.

So, summarizing:

For the quadratic part f2(x):

- If a > 0: range is [a³, ∞)
- If a < 0: range is (-∞, 0]
- If a = 0: range is {0}

For the linear part f1(x):

- If a > 0: range is (-∞, a(a + 2))
- If a < 0: range is (a(a + 2), ∞)
- If a = 0: range is {0}

Therefore, the total range of f(x) is the union of the ranges of f1(x) and f2(x). So, to have the entire real line covered, the union of these two ranges must be ℝ. Let's analyze for different cases of a.

First, let's consider a > 0. Then:

- f1(x) has range (-∞, a(a + 2))
- f2(x) 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 upper bound of the first interval and the lower bound of the second interval overlap or meet. That is, we need that a(a + 2) ≥ a³. Because if a(a + 2) ≥ a³, then the two intervals overlap or meet, so their union is (-∞, ∞). Wait, but if a(a + 2) ≥ a³, then the upper bound of the first interval is greater than or equal to the lower bound of the second interval. Therefore, the union would be (-∞, ∞). 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 a > 0, the condition is a(a + 2) ≥ a³. Let's solve this inequality:

a(a + 2) ≥ a³

Subtract a³ from both sides:

a(a + 2) - a³ ≥ 0

Simplify:

a² + 2a - a³ ≥ 0

Rearranged:

- a³ + a² + 2a ≥ 0

Multiply both sides by -1 (which reverses the inequality):

a³ - a² - 2a ≤ 0

Factor:

a(a² - a - 2) ≤ 0

Which factors further:

a(a - 2)(a + 1) ≤ 0

So, we have the inequality a(a - 2)(a + 1) ≤ 0. Let's find the intervals where this holds.

First, find the critical points: a = -1, 0, 2.

We can make a sign chart:

Intervals:

1. a < -1
2. -1 < a < 0
3. 0 < a < 2
4. a > 2

Test each interval:

1. a < -1: Let's pick a = -2. Then (-2)(-2 - 2)(-2 + 1) = (-2)(-4)(-1) = (-2)(4) = -8 < 0. So the inequality holds here.

2. -1 < a < 0: Let's pick a = -0.5. Then (-0.5)(-0.5 - 2)(-0.5 + 1) = (-0.5)(-2.5)(0.5) = (-0.5)(-1.25) = 0.625 > 0. So the inequality does not hold here.

3. 0 < a < 2: Let's pick a = 1. Then (1)(1 - 2)(1 + 1) = (1)(-1)(2) = -2 < 0. So the inequality holds here.

4. a > 2: Let's pick a = 3. Then (3)(3 - 2)(3 + 1) = 3*1*4 = 12 > 0. So the inequality does not hold here.

Additionally, check the critical points:

At a = -1: (-1)(-1 - 2)(-1 + 1) = (-1)(-3)(0) = 0. So equality holds.

At a = 0: 0*(...)=0. Equality holds.

At a = 2: 2*(0)*(3) = 0. Equality holds.

Therefore, the inequality a(a - 2)(a + 1) ≤ 0 holds for a ∈ (-∞, -1] ∪ [0, 2].

But remember, we were considering the case where a > 0. Therefore, in this case, the inequality holds for a ∈ (0, 2]. Therefore, for a > 0, the condition that the union of the ranges is ℝ is satisfied when a ∈ (0, 2].

But we need to check if at a = 2, the union is indeed ℝ. Let's check:

At a = 2:

For f1(x): range is (-∞, 2*(2 + 2)) = (-∞, 8)

For f2(x): range is [2³, ∞) = [8, ∞)

Therefore, the union is (-∞, 8) ∪ [8, ∞) = ℝ. Perfect, so there's no gap. Therefore, for a in (0, 2], the union of the ranges is ℝ. Therefore, for a > 0, the maximum value of a is 2.

But we need to check other cases as well. Let's check for a < 0.

Case 2: a < 0.

For a < 0:

- f1(x) has range (a(a + 2), ∞)
- f2(x) has range (-∞, 0]

Therefore, the union of these two ranges is (-∞, 0] ∪ (a(a + 2), ∞). For this union to be all real numbers, we need that the upper bound of the first interval (which is 0) and the lower bound of the second interval (which is a(a + 2)) overlap or meet. That is, we need that a(a + 2) ≤ 0. Because if a(a + 2) ≤ 0, then the second interval starts at a(a + 2) which is ≤ 0, and since the first interval goes up to 0, the union would be (-∞, ∞). Wait, let me think again.

Wait, the first interval is (-∞, 0], and the second interval is (a(a + 2), ∞). For their union to be all real numbers, we need that the second interval starts at a(a + 2) ≤ 0, so that (a(a + 2), ∞) includes all numbers greater than a(a + 2). But since the first interval already covers up to 0, if a(a + 2) ≤ 0, then the second interval starts at some value ≤ 0, so the union would be (-∞, ∞). Wait, but if a(a + 2) is less than 0, then (a(a + 2), ∞) includes all numbers greater than a(a + 2), which includes numbers from a(a + 2) to ∞. Since the first interval is (-∞, 0], then the union would be (-∞, ∞) if a(a + 2) ≤ 0. Because if a(a + 2) ≤ 0, then (a(a + 2), ∞) includes all numbers greater than a(a + 2), which includes numbers from a(a + 2) to ∞. Since the first interval covers up to 0, and the second interval covers from a(a + 2) to ∞, then if a(a + 2) ≤ 0, then the union is (-∞, ∞). However, if a(a + 2) > 0, then there is a gap between 0 and a(a + 2). Therefore, the condition is a(a + 2) ≤ 0.

So, solving a(a + 2) ≤ 0 for a < 0.

Let me solve the inequality a(a + 2) ≤ 0.

The critical points are a = -2 and a = 0. Since we are considering a < 0, the interval is a ∈ (-∞, 0). The inequality a(a + 2) ≤ 0 holds when a ∈ [-2, 0]. Therefore, for a < 0, the inequality holds when a ∈ [-2, 0). Therefore, for a ∈ [-2, 0), the union of the ranges is ℝ. Therefore, for a < 0, the maximum value of a is approaching 0 from the left, but since we are looking for the largest value of a overall, which could be in the positive case (a=2) or in the negative case (a approaching 0). Since 2 is larger than 0, the maximum a is 2. However, we need to check if there are other cases.

Case 3: a = 0. Then, both f1(x) and f2(x) have range {0}. Therefore, the total range is {0}, which is not all real numbers. Therefore, a = 0 is invalid.

Therefore, so far, for a > 0, the maximum a is 2, and for a < 0, the maximum a is approaching 0. Therefore, the overall maximum a is 2. However, we need to check if there are any other constraints or if there's a case where even though the union of ranges is ℝ, there's some other issue. Wait, but the problem says "the graph of y = f(x) intersects every horizontal line at least once". So, if the range is ℝ, then every horizontal line y = k intersects the graph at least once. Therefore, if the range is ℝ, then the condition is satisfied. Therefore, for a ∈ (0, 2], the range is ℝ, so the condition is satisfied. For a < -2, the range is not ℝ. For a between -2 and 0, the range is ℝ. Therefore, the maximum value of a is 2. However, let me check for a = -2. Let me check if a = -2 is allowed.

For a = -2:

First, check the ranges.

For f1(x) = ax + 2a = -2x + 2*(-2) = -2x - 4. The domain is x < a = -2. Therefore, the range of f1(x) is (a(a + 2), ∞) = (-2*(-2 + 2), ∞) = (-2*(0), ∞) = (0, ∞). Wait, but earlier I thought that for a < 0, the range of f1(x) is (a(a + 2), ∞). Let me check that again.

Wait, for a < 0, f1(x) = ax + 2a = a(x + 2). The domain is x < a. So, as x approaches negative infinity, since a is negative, ax + 2a approaches positive infinity. As x approaches a from the left, f1(x) approaches a(a + 2). Therefore, the range is (a(a + 2), ∞). For a = -2, that would be (-2*(-2 + 2), ∞) = (-2*(0), ∞) = (0, ∞).

For f2(x) = ax² = -2x² for x ≥ a = -2. The domain is x ≥ -2. Since a = -2 < 0, the parabola opens downward. The maximum value is at x = 0, which is 0. As x approaches infinity, f2(x) approaches negative infinity. Therefore, the range of f2(x) is (-∞, 0]. Therefore, the union of (0, ∞) and (-∞, 0] is ℝ. Therefore, for a = -2, the range is ℝ. Therefore, a = -2 is allowed. However, since we are looking for the largest value of a, which is 2, which is larger than -2, so 2 is still the maximum.

But let me check if there's a case where even though the union of ranges is ℝ, there's a problem with the function not intersecting some horizontal line. Wait, but if the range is ℝ, then every horizontal line y = k intersects the graph. Therefore, the condition is satisfied. Therefore, the maximum a is 2. However, let me check for a = 2, whether the function actually meets every horizontal line.

For a = 2:

f(x) is:

- 2x² for x ≥ 2

- 2x + 4 for x < 2

So, for the linear part, x < 2, f(x) = 2x + 4. The range of this part is (-∞, 2*2 + 4) = (-∞, 8). For the quadratic part, x ≥ 2, f(x) = 2x², which has range [2*(2)^2, ∞) = [8, ∞). Therefore, the union is (-∞, 8) ∪ [8, ∞) = ℝ. Therefore, every horizontal line intersects the graph.

But let me check for a value of k = 8. The horizontal line y = 8 intersects the graph at x = 2 (from the quadratic part) and also, does it intersect the linear part? Let's see. For the linear part, solving 2x + 4 = 8 gives x = 2. But x = 2 is not in the domain of the linear part (x < 2). Therefore, the only intersection is at x = 2 from the quadratic part. Therefore, even though the ranges meet at 8, the function is continuous at x = 2? Wait, earlier when we checked continuity, for a = 2, the left-hand limit is a² + 2a = 4 + 4 = 8, and the right-hand limit is a³ = 8. Therefore, the function is continuous at x = 2. Therefore, the point x = 2 is included in the quadratic part, so y = 8 is achieved at x = 2. Therefore, the horizontal line y = 8 intersects the graph at x = 2. Therefore, it's okay.

But what if a was slightly less than 2? Let's say a = 1.9. Then, the linear part would have range (-∞, 1.9*(1.9 + 2)) = (-∞, 1.9*3.9) ≈ (-∞, 7.41). The quadratic part would have range [a³, ∞) ≈ [6.859, ∞). Therefore, the union is (-∞, 7.41) ∪ [6.859, ∞) = (-∞, ∞). Therefore, there is an overlap between 6.859 and 7.41, so the union is ℝ. Therefore, even for a < 2, the union is ℝ. However, when a = 2, the two ranges meet exactly at 8, so there's no gap. Therefore, a = 2 is acceptable.

But let me check if there's a case where even though the union of ranges is ℝ, there's a horizontal line that doesn't intersect the graph. Wait, but if the union of the ranges is ℝ, then for any k ∈ ℝ, there exists some x such that f(x) = k. Therefore, the horizontal line y = k intersects the graph. Therefore, the condition is satisfied. Therefore, the maximum value of a is 2.

But let me check for a = 2, if there's any horizontal line that doesn't intersect. For example, take k = 7.5. Since the linear part goes up to 8, and the quadratic part starts at 8. So, 7.5 is between 6.859 and 8. Wait, for a = 2, the quadratic part starts at 8. So, the linear part goes up to 8, and the quadratic part starts at 8. Therefore, the value 7.5 is between the upper bound of the linear part (which is 8) and the lower bound of the quadratic part (which is 8). Wait, but if the linear part approaches 8 as x approaches 2 from the left, and the quadratic part starts at 8 when x = 2, then the value 7.5 is less than 8. Therefore, 7.5 is in the range of the linear part. Wait, the linear part's range is (-∞, 8). Therefore, 7.5 is in that range. Therefore, there exists an x < 2 such that 2x + 4 = 7.5. Solving: 2x + 4 = 7.5 => 2x = 3.5 => x = 1.75, which is less than 2. Therefore, it's valid. Similarly, for k = 8, as discussed, it's achieved at x = 2. For k = 9, it's achieved by the quadratic part. For k = -5, it's achieved by the linear part. Therefore, all horizontal lines are covered. Therefore, a = 2 is valid.

But let me check if there's a case where even though the union of ranges is ℝ, the function might not actually reach certain values. For example, suppose that the two pieces don't actually meet at the overlapping point. Wait, but in the case of a = 2, they meet at 8. For a < 2, the upper bound of the linear part is less than the lower bound of the quadratic part? Wait, no. Wait, for a < 2, the upper bound of the linear part is a(a + 2), and the lower bound of the quadratic part is a³. So, for a in (0, 2), we have a(a + 2) ≥ a³, so the upper bound of the linear part is greater than or equal to the lower bound of the quadratic part. Therefore, the union is ℝ. Therefore, there is no gap. Therefore, for a in (0, 2], the union is ℝ. Therefore, the maximum a is 2.

But let me check for a = 1. Let's take a = 1. Then:

Linear part: range is (-∞, 1*(1 + 2)) = (-∞, 3)

Quadratic part: range is [1³, ∞) = [1, ∞)

Therefore, union is (-∞, 3) ∪ [1, ∞) = ℝ. Therefore, yes, it works. For example, k = 2 is in both ranges. For k = 0, it's in the linear part. For k = 4, it's in the quadratic part. So, all horizontal lines are covered.

But let me check for a = 2. Suppose someone says, "Wait, what about the value k = 8? It's achieved at x = 2. But what if there's a horizontal line that is tangent to the graph or something?" But no, the problem just requires that every horizontal line intersects the graph at least once. It doesn't require that they intersect exactly once or anything else. So, even if a horizontal line is tangent, it still intersects once. Therefore, it's okay.

But let me think again. Suppose that for some a, the function is not surjective. For example, if a is too small. For example, if a = 1/2. Then, the linear part has range (-∞, (1/2)(1/2 + 2)) = (-∞, (1/2)(5/2)) = (-∞, 5/4). The quadratic part has range [ (1/2)^3, ∞ ) = [1/8, ∞). Therefore, the union is (-∞, 5/4) ∪ [1/8, ∞) = ℝ. Therefore, even though there is an overlap between 1/8 and 5/4, the union is ℝ. Therefore, it's okay.

But if a is less than 0, say a = -1. Then:

For a = -1:

Linear part: range is (a(a + 2), ∞) = (-1*(-1 + 2), ∞) = (-1*(1), ∞) = (-1, ∞)

Quadratic part: range is (-∞, 0]

Therefore, union is (-∞, 0] ∪ (-1, ∞) = ℝ. Therefore, it's okay. For example, k = -0.5 is in the quadratic part, k = 0.5 is in the linear part, etc.

But if a = -3:

For a = -3:

Linear part: range is (a(a + 2), ∞) = (-3*(-3 + 2), ∞) = (-3*(-1), ∞) = (3, ∞)

Quadratic part: range is (-∞, 0]

Therefore, union is (-∞, 0] ∪ (3, ∞). Therefore, there is a gap between 0 and 3. Therefore, horizontal lines between 0 and 3 do not intersect the graph. Therefore, a = -3 is invalid. Therefore, for a < -2, the union is not ℝ. Therefore, the condition is only satisfied for a ∈ [-2, 0) ∪ (0, 2]. But since we are looking for the largest a, which is 2.

But let me check for a = -2. As before, for a = -2:

Linear part: range is (a(a + 2), ∞) = (-2*(0), ∞) = (0, ∞)

Quadratic part: range is (-∞, 0]

Therefore, union is (-∞, 0] ∪ (0, ∞) = ℝ. Therefore, it's okay. Therefore, a = -2 is valid. However, since we are looking for the largest a, which is 2, which is greater than -2, so 2 is still the maximum.

But let me check if there's a case where even for a between -2 and 0, there's some problem. For example, take a = -1. Then, as above, the union is ℝ. Therefore, it's okay. Therefore, the maximum a is 2.

But let me check if there's a case where even though the union of ranges is ℝ, the function might not actually achieve some values. For example, suppose that the two pieces don't actually cover the entire range. Wait, but we already considered the ranges. For example, for a > 0, the linear part covers (-∞, a(a + 2)) and the quadratic part covers [a³, ∞). If a(a + 2) ≥ a³, then the union is ℝ. Therefore, for any k in ℝ, if k ≤ a(a + 2), then it's covered by the linear part, and if k ≥ a³, it's covered by the quadratic part. Since a(a + 2) ≥ a³, then for k between a³ and a(a + 2), it's covered by both. Therefore, there's no problem. Therefore, the function is surjective.

Therefore, the conclusion is that the largest value of a is 2.

But let me check if there's a possibility that for a > 2, the function does not cover all real numbers. For example, take a = 3. Then:

Linear part: range is (-∞, 3*(3 + 2)) = (-∞, 15)

Quadratic part: range is [3³, ∞) = [27, ∞)

Therefore, the union is (-∞, 15) ∪ [27, ∞). Therefore, there is a gap between 15 and 27. Therefore, horizontal lines between 15 and 27 do not intersect the graph. Therefore, a = 3 is invalid. Therefore, for a > 2, the function does not cover all real numbers. Therefore, the maximum a is indeed 2.

Therefore, the answer is 2. However, let me check once again for a = 2, if there's any possible horizontal line that doesn't intersect. For example, take k = 8. As discussed, it's achieved at x = 2. For k = 7.5, achieved by the linear part. For k = 9, achieved by the quadratic part. For k = -10, achieved by the linear part. Therefore, all horizontal lines are covered. Therefore, a = 2 is valid.

Therefore, the largest value of a is 2.

**Final Answer**
The largest value of $ a $ is $\boxed{2}$.

To determine the **largest value of $ a $** such that the graph of the piecewise 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 must ensure that the **range of $ f(x) $** is the entire set of real numbers $ \mathbb{R} $.

---

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

The function is defined in two parts:

- **For $ x \geq a $:** $ f(x) = ax^2 $, a quadratic function.
- **For $ x < a $:** $ f(x) = ax + 2a $, a linear function.

We'll analyze the **range** of each piece and then consider their **union** to determine when the total range is $ \mathbb{R} $.

---

### Step 2: Determine the Range of Each Piece

#### **Case 1: $ a > 0 $**

- **Quadratic part:** $ f(x) = ax^2 $ for $ x \geq a $.
  - Since $ a > 0 $, the parabola opens upwards.
  - The minimum value occurs at $ x = a $: $ f(a) = a^3 $.
  - As $ x \to \infty $, $ f(x) \to \infty $.
  - So, the range is $ [a^3, \infty) $.

- **Linear part:** $ f(x) = ax + 2a $ for $ x < a $.
  - As $ x \to -\infty $, $ f(x) \to -\infty $.
  - As $ x \to a^- $, $ f(x) \to a(a + 2) $.
  - So, the range is $ (-\infty, a(a + 2)) $.

- **Union of ranges:**
  $$
  (-\infty, a(a + 2)) \cup [a^3, \infty)
  $$
  For this 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
  $$
  Factor:
  $$
  a(a^2 - a - 2) \leq 0 \Rightarrow a(a - 2)(a + 1) \leq 0
  $$

  The critical points are $ a = -1, 0, 2 $.
  The inequality holds for:
  $$
  a \in (-\infty, -1] \cup [0, 2]
  $$

  Since we are considering $ a > 0 $, the valid interval is:
  $$
  a \in (0, 2]
  $$

  So, for $ a \in (0, 2] $, the union of the ranges is $ \mathbb{R} $, and the function intersects every horizontal line.

---

#### **Case 2: $ a < 0 $**

- **Quadratic part:** $ f(x) = ax^2 $ for $ x \geq a $.
  - Since $ a < 0 $, the parabola opens downward.
  - The maximum value occurs at $ x = 0 $: $ f(0) = 0 $.
  - As $ x \to \infty $, $ f(x) \to -\infty $.
  - So, the range is $ (-\infty, 0] $.

- **Linear part:** $ f(x) = ax + 2a $ for $ x < a $.
  - As $ x \to -\infty $, $ f(x) \to \infty $.
  - As $ x \to a^- $, $ f(x) \to a(a + 2) $.
  - So, the range is $ (a(a + 2), \infty) $.

- **Union of ranges:**
  $$
  (-\infty, 0] \cup (a(a + 2), \infty)
  $$
  For this to be $ \mathbb{R} $, we must have:
  $$
  a(a + 2) \leq 0
  $$
  Solve:
  $$
  a(a + 2) \leq 0 \Rightarrow a \in [-2, 0]
  $$

  So, for $ a \in [-2, 0] $, the union of the ranges is $ \mathbb{R} $, and the function intersects every horizontal line.

---

#### **Case 3: $ a = 0 $**

- Both pieces become constant:
  - $ f(x) = 0 $ for all $ x $.
  - So, the range is $ \{0\} $, which is not $ \mathbb{R} $.

---

### Step 3: Determine the Largest Valid $ a $

From the above:

- For $ a \in (0, 2] $, the function intersects every horizontal line.
- For $ a \in [-2, 0] $, the function also intersects every horizontal line.
- But since we are asked for the **largest** value of $ a $, the maximum is:
  $$
  \boxed{2}
  $$

---

### 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]