It does not matter whether the particle gained mass or velocity, the kinetic energy is always defined
$$K = \frac{1}{2} m v^2$$
What is wrong with this approach?
The energy is lost to perfect inelastic collision. The total work done needs to account for this energy loss, and also give the kinetic energy to the added mass
$$W = \frac{1}{2} M v^2 + E_\text{lost}$$
where $M$ is the total added mass. You have already (correctly) concluded that $E_\text{lost}$, but we can show that from the perfect inelastic collision
$$(m \cdot v) + (dm \cdot 0) = (m + dm) v'$$
where $m$ is mass of the cart plus sand added up until that point in time, $v$ is the cart velocity maintained at constant value by applying force $F = v \cdot dm/dt$, $dm$ is additional sand we put into the cart, and $v'$ is new velocity due to perfect inelastic collision
$$v' = \frac{m}{m + dm} v$$
The lost kinetic energy is
$$dE = \frac{1}{2} m v^2 - \frac{1}{2} (m + dm) v'^2 = \frac{1}{2} m v^2 \frac{dm}{m + dm}$$