Editorial for RGPC '18 P1 - Giant Cookie

Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Author: tiffie44

To determine if Elton will share the cookie, the modulo operation (%) can be used to check if the cookie pieces can be divided amongst the members without any remainder. If so, the number of pieces each person will get can be found with simple division.

Otherwise, the answer is found by looping to find a greater number of people that now allows the cookie to be shared, again using modulo. Note that looping from M + 1 will ensure that the smallest valid answer is found. The smallest number of additional people needed is the difference between the found value and the number of club members present.

Time complexity: \mathcal{O}(N)


There are no comments at the moment.