MOON - Editorial

let the number of truffles with first elf be N_1 & number of candies be M_1 .
Hence total sweetness with 1st elf will be equal to N_1X+M_1Y
Now the combined total sweetness of both the elves will be NX+MY .Now inorder to have equal amounts of sweetness each elf is bound to have a total sweetness of (NX+MY)/2 .
so from above 2 relations we can say that
N_1X+M_1Y = (NX+MY)/2
2N_1X+2M_1Y=NX+MY
M1=(NX+MY-2N_1X)/2Y
Now what I have done is to iterate through all values of possible values of N_1 (from 0 to N) and for each N_1 I am checking if we get a non negative integral value of M_1 which is less than or equal to M if we get this kind of value of M_1 we print "YES" and return else print "NO" after checking all values of N_1.I have tackled all the corner cases of like X=0 ,Y=0…etc separately .

1 Like