Assume speed of A is Va and speed of B is Vb.
IF they are moving in the same direction.
5 (Va -Vb) = (100)
Va -Vb = 20 ....(i)
If they move in the opposite direction.
Va + Vb = 100 ...(ii)
Equation (i) + Equation (ii)
2 Va =120
Va = 60 km/hr
Vb = 40 km/hr
Henc speed of A is 60km/hr and speed of B is 40 km/hr.