Binary Search - Algorithms for Competitive Programming
When it is impossible to pick$M$, that is, when$R = L + 1$, we directly compare$k$with$A_L$and$A_R$. Otherwise we would want to pick$M$in such manner that it reduces the active segment to a single element as quickly as possiblein the worst case. ...