My doubt is related to the given SPOJ problem
I was able to come up with idea of using Binary Search but struggled with the positioning of the cows. After watching some solutions like this one , almost all of them were placing the first cow at the first stall stating its a greedy approach which works.
I am unable to understand what exactly are we being greedy about as what matters to us is the distance between the cows and not where the cows are placed(i.e we can place 3 cows in the two valid given orders where both give a minimum distance of 2
(4,6,10))so what is the necessity of placing the first cow at first position.
Also even if there is some reason behind this approach ,how does it guarantee that for a chosen distance
dist if we can’t place the given number of cows (the fist cow being placed at first stall)with
dist as the minimum distance then there is no other way of placing the cows(the order in which placing starts from any stall) which would satisfy the conditions.