In these sorts of problems you can't take the simple approach, you've got to come up with a clever way to avoid actually simulating the eating of the candy bars.
Some hints (in rot13), for practice see how few hints you can use.
Gel cevagvat bhg juvpu onef ner rngra naq frr vs lbh pna frr n cnggrea.
Va lbhe fnzcyrf ybbx ng juvpu pnaql one vf gur svefg bar ercrngrq.
Lbh pna cebir guvf erfhyg ol pbafvqrevat jung unccraf nsgre lbh'ir fgnegrq ercrngvat pnaql onef, naq pbafvqrevat jurgure be abg bgure jnlf bs ernpuvat gur svany cbfvgvba ner cbffvoyr.
Pna lbh rkcerff gur ehyr sbe jura gur plpyr ercrngf zngurzngvpnyyl?
Qb lbh xabj gur zngurzngvpny anzr sbe gur svefg ahzore gung svgf gur ehyr?
This is one of the posted answers to this question: Improving the time complexity of my program
I can understand the reasoning behind not wanting to outline all of the points and straight give away the entire solution, as that would potentially rob the asker of the learning process. But is posting an answer like this really appropriate?
Would it be okay if the answer were in Spanish?
Would it be okay if the answer were encrypted using a less trivial encryption?
And finally, what's wrong with using the spoiler tags?
This is a spoiler!
This is another spoiler!
I can now allow a user to limit himself to as many or few hints as they choose without this answer being a pain to decrypt for someone who wants to read the whole answer but doesn't have a decrypter/translater quickly accessible.