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?

You are forgetting that 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}$$

By rearranging the above equation we get

$$m \cdot dE + dm \cdot dE = \frac{1}{2} m v^2 \cdot dm$$

We can neglect the product of two infinitesimally small values $dm \cdot dE \approx 0$ which gives

$$dE = \frac{1}{2} v^2 \cdot dm$$

By integrating the above equation we finally get that the total energy lost in inelastic collision is

$$\boxed{E_\text{lost} = \frac{1}{2} M v^2}$$