SPOJ - Problem AGGRCOW - Aggressive cows

I have the same doubt. Did you find the answer?

Lets take 5 stalls s1->s5, sorted according to their positions.
We define dist(s[i]) as the minimum dist from s[i] to its nearest two stalls.
We first choose the first two stalls which are s1,s5.
To choose the 3rd stall we use binary search and lets assume it turns out to be s3, which makes s1,s5 as its nearest two stalls.
The next two stalls-> s2,s4 are found out using priority queue and binary search, but as soon as we choose s2, s4 the dist(s3) has changed,its no longer what we assumed it to be, now it needs to recalculated using s2,s4 as the nearest two stalls which is not done by the given algorithm.
That’s why its fails!!