https://www.codechef.com/viewsolution/27841610 :: here is the link, I am getting WA in subtask 2 and cant figure out the mistake whatsoever.

Appoach: Used dp to figure out whoi s alice and who is bob and then simple map,array calculations to find out x,fx,n,m for bob,alice respectively.