Packaging Cupcakes (MUFFINS) memory used

Problem link:: http://www.codechef.com/problems/MUFFINS3

I have solved this question, but the memory my code uses is 2.2M. Where as the memory used by a lot of other solution to this problem in C, use 1.6M.
I saw their approach and its the same.

Then why is my code taking up more memory??

My code link:: http://www.codechef.com/viewsolution/4661576

1.6M memory code link:: http://www.codechef.com/viewsolution/1729066

Please help guys. Thanks for any help in advance.

HI @coderzz027. 2.2 and 1.6M is not the exact memory used by your code.In an online judge ,For each language , there is some pre-defined memory which is always allotted to your code its 2.2M for latest version of C,4M for Python, 3.2 for C++ and so on. Now your code starts execution with this initial memory. Whenever your code needs extra memory above this initial allotted memory, then it is allocated as required but it will always have this initial amount. So memory consumed by your code =

max(Initial Allotted memory, Actual memory consumed)

In your case, actual memory is less than 2.2 M so it shows 2.2 M.In earlier versions of C, 1.6M was allocated instead of 2.2 and their code consumed less than 1.6 so it shows 1.6. Don’t worry, your code is optimal and uses little memory. It’s just that the judge works this way.

1 Like

@kcahdog - Thank you… :slight_smile:

//