Packaging the cupcakes problem code-MUFFINS3

please help me to understand this question. I Know this is very basic one. but I could understand this.

what we need to do actually… I don’t get thoughts how solve so i saw few submissions and got to know dividing by 2+1 but why…

is it good to see submissions if i don’t get how to solve or couldn’t understand the problem.

I might have missing concepts I think. is it the reason I am not getting thoughts to solve or unable to understand? please give suggestions and good youtube tutorials to improve concepts in DS and algo.

Thanks a lot in advance.

In the problem, you just have to maximize the remainder. For this A should be n/2+1.

If you couldn’t understand/solve the problem, you should post the problems here for the explanation or some hints for the problems and then you should try it on your own instead of direct jumping to the solutions.
I would recommend you to go through DSA learning series and the video lectures related to it on youtube.
You can google up stuffs anytime whenever you are stuck. Read stuffs from , and many more.
You can refer to the syllabus followed in the codechef DSA programme

Thank you very much rupinder… but how will we know maximize the remainder based on the question?

Didn’t get ur question. Could u explain?

As u said earlier, we have to maximize the remainder so we are doing n/2+1…

how do we get to know we have to maximize the remainder from question?

Lets us assume you have n cupcakes and you want exactly x cupcakes in each package.
so you will check whether n is more than x or not. If yes, then you will place x muffins in a package. Now you are left with n-x muffins. Now you will again check whether number of muffins is more than a or not. and so on.
The final equation will be:
where b is the number of the packages filled with muffins, r is the remaining muffins.
The chef will eat the remaining muffins. As per the question,we have to choose x such that chef can eat as many muffins as possible.
so basically we have to maximize the value of r.
Hope it helps!!

Thank you very much.

as you said we have to maximize r but i am not getting how to maximize r. I have think about it but i have not got it. Can you explain how to maximize r.

As I mentioned earlier,the equation is n=b×x+r, so we can say the remainder when n is divided by x is r ( 0<= r <= x-1 ) , iterate over all the values of x, find maximum r and you will find out that the value of x always comes out to be equal to n/2+1.
Hope it helps!!
Revert back in case of any query.

1 Like

Thank you very much…