I am stuck up with this simple problem related to averages.Please help me out in explaining the complete solution to this problem I am stuck up with this simple problem related to averages. Please help me out in explaining the complete solution to this problem.

Consider a class of $40$ students whose average weight is $40\ \mathrm{kg}$. $m$ new students join this class whose average weight is $n\ \mathrm{kg}$. If it is known that $m + n = 50$, what is the maximum possible average weight of the class now?

 A: Hint: Find the new total weight (which you claim you can find), divide by $40+m$, find the $m$ maximizing the expression!
A: The new average is given by:
$$NA=\frac{40\cdot 40+m\cdot n}{40+m}$$
Once $m+n=50→n=50-m$ then
$$NA=f(m)=\frac{1600+50m-m^2}{40+m}=90-m-\frac{2000}{40+m}$$
In order to find the maximum you can do $f'(m)=0$.
Can you finish?
A: After the join, the new sum is
\begin{align*}
&(40)(40) + mn\\[6pt]
=\; &1600 + mn\\[6pt] 
=\; &1600 + m(50-m)
\end{align*}
and the new average is
$$f(m) = \frac{1600 + m(50-m)}{40 + m}$$
We want to maximize $f(m)$, for positive integer values of $m$. Taking the derivative, we get
$$f^{\prime}(m) = \frac{-m^2 - 80m + 400}{\left(m + 40\right)^2}$$
which has two real roots, but only one positive real root, $\,r = -40 + 20\sqrt{5} \approx 4.72$.

From the algebraic form of $f^{\prime}(m)$, it follows that


*

*$0 < m < r \implies f^{\prime}(m) > 0$

*$m > r \implies f^{\prime}(m) < 0$


Since $m$ is required to be a positive integer, and $4 < r < 5$, it follows that the optimal $m$ must be either $4$ or $5$. 

Comparing $f(4)$ and $f(5)$, we find
$$f(4) = \frac{446}{11} < f(5) = \frac{365}{9}$$
It follows that the maximum possible new average is 
$$f(5) = \frac{365}{9} = 40 + \frac{5}{9} \approx 40.56$$
A: m+n = 50
The average weight with the new students will be
$AvW = \frac {40\cdot 40 + m\cdot n}{40+m}$
maximize $AvW$ constrained by $m+n = 50
$n = 50-m$
$AvW = \frac {40\cdot 40 + m\cdot (50-m)}{40+m}$
Will be optimized when $\frac {d}{dm} AvW = 0$
A: My simple approach to the question:
Every new joinee should contribute to maximize average weight.
Therefore contribution if $1$ student joins $= 1 \times 9 = 9$ kg
And this will be maximum when both the variable is equal i.e., $5 \times 5 = 25$
Therefore maximum average weight $= 40 + \frac{25}{45} \approx 40.56$ kg
