In this problem (https://www.spoj.com/problems/AGGRCOW/) why do we greedily place the first cow in the first position, there could also be a possibility that the minimum maximum distance can be acheived by placing the first cow at any other position.
Aggressive Cows is really a very nice problem, taught me a lot about Binary Search.
Anyway, to answer your question. Placing the first cow at the first position gives us a better result than placing it anywhere else. Basically our goal is to place the cows as far as possible from each other while fitting every cow in the barn. The way to achieve an optimal setting of such is to Binary Search over the range of possible distances and select the one which satisfy both the two criteria. I will not go into detail of the implementation as I believe you already know it, since you are asking the question.
Anyway, suppose you have chosen some distance ‘K’ and now want to test whether or not you can place every cow at a distance of K from each other and yet fit all the cows in the barn. Now, it is better for you to place the first cow at the first position because it buys you some more distance to place other cows, if you don’t place the first cow at the first position you will waste some extra space - the space to the left of the first cow. You could have used this space to place more cows in the barn! So, by not placing the first cow in the first position you my end up failing the test for many such values of K even though when it actually passes.
PS: You must first ofcourse read through the solutions online (Raziman TV has written a nice answer on Quora, also follow the TopCoder Binary Search tutorial).
Problem solved here:
Read the answer by Raziman T.V.