SRM 706, D2, 250-Pointer (ThreeIncreasing)

James S. Plank

Sun Jan 29 20:47:00 EST 2017
Try this on your own. If you get stuck, return here and read what I've written below.



























































This is a problem that you simply have to think about in the right order. First off, think about when will you return -1? Answer these questions, and go ahead and write code to return -1 when you have to. Your code should work on examples 2 and 3.

Now, assume that you're in a situation when you are not returning -1. Answer this question:

Is there ever a time when you would ever eat candies from the third box?

You should see that the answer to this is, "no." So, the first thing to do is eat just enough candies so that b is less than c. And the second thing to do is eat just enough candies to that a is less than b. And you're done.