The ball on the straight track retains essentially the same velocity and the same kinetic energy throughout the length of its run, the kinetic energy from the spring. The ball on the dipped track, however, has a more complex path. When it goes downhill, it gains kinetic energy from gravitational potential, accelerating it. It travels along the lower section of track with this increased kinetic energy, and thus greater velocity. The ball then goes uphill again, losing that additional kinetic energy – it has returned to the same height, so the principle of conservation of energy dictates that it must return to the same gravitational potential as before, giving up kinetic energy equal to what it gained. It now has only the same kinetic energy it started with, as imparted by the spring. So its velocity is now the same as its starting velocity, and the same as the velocity of the other ball.
However, during the time it was on the lowered section track, it had greater kinetic energy and greater velocity, so it traveled that distance faster than the ball on the straight track. And thus the ball on the dipped track reaches the end first, but with the same final velocity and the same final kinetic energy.