I have a feeling things are getting more and more confused - partly my fault for not reading properly.
The first step in any scientific problem solving is to define the problem - here, that means describing it mathematically.
Start by giving a variable name to every physical thingy mentioned in the problem ... with practise you'll add them in mentally as you read; like this:
A 20.0-kg block ##m## is connected to a 30.0-kg block ##M## by a string that passes over a light frictionless pulley. Block M is connected to a spring that has negligible mass and a force constant ##k## of 250 N/m. The spring is unstretched when the system is as shown in the figure,
... notice that in the diagram, the two blocks are at about the same vertical position ... sort of.
It does not actually matter. Conservation of energy arguments will only care about the
change in height, not the absolute height.
... and the incline (angle ##\theta = 40^\circ## to horizontal) is frictionless. Block m is pulled ##x=+20.0##cm down the incline (taking ##x=0## at the position the spring is unstretched and the ##+x## direction is down the ramp) ... so that M is ##y_0=40.0##cm above the floor and released from rest. Find the speed of each block when M is ##y_1=20.0##cm above the floor (that is, when the spring is, again, unstretched.)
... does that help?
Restating: I've used ##x## for the m position
downwards along the incline and ##y## for the M height
upwards from the floor.
Notice that moving m 20cm down
along the incline rises M 20cm above it's initial position... which is correct because the string does not stretch.
... In maths we say: ##\Delta x = \Delta y## Let's call that ##\Delta y = \Delta x = h = 20##cm and just use "h" ... avoids writing out deltas.
So the change in the height of m is ##h\sin\theta## ... the sine of 40deg is not a nice number so I'll just have to leave it.
Here's the physics:
The initial setup stores energy in the spring, and as gravity in M, this energy is released, going to kinetic energy in both blocks but some is used lifting block m.
In maths, that looks like this:
##\qquad \frac{1}{2}kh^2 + Mgh = \frac{1}{2}(M+m)v^2 + mgh\sin\theta##
(I wrote the equation out in the same order as I described the terms above notice?)
... solve for v and you are done.
Notice how there is no need to refer to the absolute height of either block?
Also: no sleight of hand needed.
I don't normally do the problem for you but I think this is an exception - the example, since you've worked on it so much, hopefully will help you focus better in future.