Kinetic energy lost = Thermal energy gained...
So now the 2 bodies collide. When they collide inelastically we can calculate the velocity of the 2 bodies after collision
m1v1 + m2v2 = (m1+m2)v' (remember the sign conventions it will eventually end up as 10*10-20*20=(20+10)v'. Now we've got the net velocity then we calculate the new kinetic energy as 1/2mv'2 which amounts upto 1500J. Subtarct this from the initial kinetic energies of the 2 bodies and we get the kinetic energy lost which gives thermal energy gained
the final answer is 4500J-1500J=3000J