Spoj AGGRESIVE COWS

Please help to solve this problem on spoj, can’t understand how to use binary search.

Check out this link

https://www.quora.com/What-is-the-correct-approach-to-solve-the-SPOJ-problem-Aggressive-cow

2 Likes

Simple binary search is a technique which simply finds whether an element is present in a (sorted) array in log(N) time.

However, it can be tweaked in order to perform a world of computations, usually involving the minimum/maximum value of some entity.

It is best explained in the following link :

Take your time, and understand the content of the blog.

Similar problems for practice :

SPOJ - EKO

Codeforces - 782B

Simple and clear explanation http://sahilmutneja.com/blog/2015/02/aggressive-cowsaggrcow-spoj/