the guard at the rear of B is passing the driver at the front of A then B has not only caught up the initial distance between the two trains but has also completely overtaken train A.
Let the original separation distance be x. Then distance to be covered starting with relative velocity zero is s = 800 + x (800m being the overtaking distance from front meets rear to rear leaves front).
Distance s covered at acceleration a starting from (relative) speed zero = 1/2 at^2 which for t=50 gives:
= 0.5 x 50^2 = 1250m
So 800 + x = 1250 Therefore x = 1250 -800 = 450m.