Hi LibrarianTurtle,Yes, exactly. When kevincan writes "n is odd,"
n is the total number of sofas (the number of terms in your set). He's pointing out that the smallest possible count - the
25 you found - comes from the
odd case, not the even one. So your reading is correct.
Now the interesting part is
why odd wins, and it comes straight out of the two setups you already built.
Where the difference lives: the median-
Odd set (2k+1): only
one sofa sits at the median of
900. Every other sofa in the lower half can be pushed all the way down to the cheapest allowed price,
400. That drives the sum as low as possible.
-
Even set (2k): the median is the
average of the
two middle sofas, so those two must together add up to
1800. You can't shove both of them down to
400 - the middle of the set is forced to carry more value.
That extra weight in the middle is the whole story. Look at your own minimum sums:
- Odd: min sum =
1300k + 2990- Even: min sum =
1300k + 2590The even case
looks cheaper per k, but it holds
2k sofas versus
2k+1, so each sofa has to average higher to hit
750 - and that constraint bites harder. Working it out, odd needs
k = 12 → 25 sofas, while even needs
k = 13 → 26 sofas.
So the minimum lands on the odd case because a single median value lets you stack the maximum number of cheap
400 sofas without disturbing the median.
Feel it with a tiny setCompare medians directly:
- Odd:
{400, 900, 2990} - the
900 is one real sofa; the
400 is free to stay at rock bottom.
- Even:
{400, x, y, 2990} with median
900 - now
x + y = 1800, so the middle can't both be
400.
Same concept, just shrunk: the odd set spends less on its middle, which is exactly why it minimizes the count.
Answer: DLibrarianTurtle
Do you mean when the number of terms is odd ?