I'm studying for a mid-term, and I'm trying to solve some mock-papers. The following are two problems which I have solved, but I'm missing a part:

$(1)$ A body of mass $ m_1= 8 \rm kg$ passes through $A$ with a speed of $v_A= 10 \rm \frac m s$, and a meight of $h_a = 5 \rm m$ relative to the floor level. The friction is neglibible all through the path, except from in $\overline{CD}=10 \rm m$ where the dynamic friction coefficient is $\mu_d=0.5$. At the end of the path there is an ideal spring of constant $K= 1000 \rm \frac N m $. Find.
$(a)$ The maximum compression of the spring when it is hit by the object. $(b)$ The distance (measured from $C$) the block travels before coming to a still while returning due to the decompression of the spring.
I have solved $(a)$ using the theorem of the work of non-conervative forces. Namely, I have that, being $D'$ the instant of maximum compression, that the work $\mathcal W$ of the non conservatives forces is equal to the change $\Delta$ of the mechanical energy:
$$\mathop \Delta \limits_{{\text{A}} \to {\text{D'}}} {{\text{E}}_{{\text{mec}}}} = \mathop {\mathcal W}\limits_{{\text{A}} \to {\text{D'}}} {{\bf{F}}_{{\text{nc}}}}$$
This translates to
$${\text{E}}_{{\text{mec}}}^{{\text{D'}}} - {\text{E}}_{{\text{mec}}}^{\text{A}} = \mathop {\mathcal W}\limits_{{\text{A}} \to {\text{D'}}} {\bf{N}} + \mathop {\mathcal W}\limits_{{\text{A}} \to {\text{D'}}} {\bf{f}}$$
Where $\rm N$ is the normal and $\rm f$ is the friction. This gives
$$\eqalign{ & \left( {\frac{1}{2}k \cdot \Delta \ell _{\max }^2 + 0 + 0} \right) - \left( {0 + \frac{1}{2}m \cdot v_A^2 + m \cdot {h_A} \cdot g} \right) = 0 + \overline {{\text{CD}}} \cdot \left\| {\text{f}} \right\| \cdot \cos 180 \cr & \left( {500\frac{{\text{N}}}{{\text{m}}} \cdot \Delta \ell _{\max }^2} \right) - \left( {0 + 4{\text{kg}} \cdot 100\frac{{{{\text{m}}^{\text{2}}}}}{{{{\text{s}}^{\text{2}}}}} + 8{\text{kg}} \cdot 5{\text{m}} \cdot 10\frac{{\text{m}}}{{{{\text{s}}^{\text{2}}}}}} \right) = - 10{\text{m}} \cdot \left\| N \right\|{\mu _d} \cr & \left( {500\frac{{\text{N}}}{{\text{m}}} \cdot \Delta \ell _{\max }^2} \right) - \left( {400{\text{J}} + 400{\text{J}}} \right) = - 10{\text{m}} \cdot m \cdot g \cdot \frac{1}{2} \cr & 500\frac{{\text{N}}}{{\text{m}}} \cdot \Delta \ell _{\max }^2 - 800{\text{J}} = - 10{\text{m}} \cdot 8{\text{kg}} \cdot 10\frac{{\text{m}}}{{{{\text{s}}^{\text{2}}}}} \cdot \frac{1}{2} \cr & 500\frac{{\text{N}}}{{\text{m}}} \cdot \Delta \ell _{\max }^2 - 800{\text{J}} = - 400{\text{J}} \cr & 500\frac{{\text{N}}}{{\text{m}}} \cdot \Delta \ell _{\max }^2 = 400{\text{J}} \cr & \Delta \ell _{\max }^2 = \frac{4}{5}{{\text{m}}^2} \cr & \Delta {\ell _{\max }} = 2\frac{{\sqrt 5 }}{5}{\text{m}} \cong 0.89{\text{m}} \cr} $$
I don't know, however, how to solve $(b)$. I suppose I need to consider the energy the body has at $C$ and see what distance it should travel so that it is exhausted by the friction.
ADD: I think one can solve it this way. ¿Are the reasonings correct? (I'm sure the calculations are)
All the elastic energy has to turn into work by the friction, which means
$$\eqalign{ & \frac{1}{2}k\cdot\Delta \ell _{\max }^2 = \overline {QC} \cdot m \cdot g\cdot{\mu _d} \cr & 500\frac{{\text{N}}}{{\text{m}}}\frac{4}{5}{{\text{m}}^{\text{2}}} = \frac{1}{2}\overline {QC} \cdot 8kg \cdot 10\frac{m}{{{s^2}}} \cr & 400{\text{N}} \cdot {\text{m}} = 40{\text{N}} \cdot \overline {QC} \cr & 10{\text{m}} = \overline {QC} \cr} $$
where $Q$ is the halting point.